Natural-Language Rendering of Structured Search Queries

ABSTRACT

In one embodiment, a method includes receiving an unstructured text query inputted by a first user, identifying one or more objects associated with the online social network matching at least a portion of the unstructured text query, accessing a context-free grammar model comprising a plurality of grammars, generating one or more structured queries, each structured query corresponding to a selected grammar of a context-free grammar model, wherein each structured query is based on a natural-language string generated by the selected grammar, each structured query comprising at least one query token corresponding to each of the identified object, and sending one or more of the structured queries as suggested queries for display to the first user in response to the unstructured text query inputted by the first user.

PRIORITY

This application is a continuation under 35 U.S.C. §120 of U.S. patentapplication Ser. No. 13/731,866, filed 31 Dec. 2012.

TECHNICAL FIELD

This disclosure generally relates to social graphs and performingsearches for objects within a social-networking environment.

BACKGROUND

A social-networking system, which may include a social-networkingwebsite, may enable its users (such as persons or organizations) tointeract with it and with each other through it. The social-networkingsystem may, with input from a user, create and store in thesocial-networking system a user profile associated with the user. Theuser profile may include demographic information, communication-channelinformation, and information on personal interests of the user. Thesocial-networking system may also, with input from a user, create andstore a record of relationships of the user with other users of thesocial-networking system, as well as provide services (e.g. wall posts,photo-sharing, event organization, messaging, games, or advertisements)to facilitate social interaction between or among users.

The social-networking system may transmit over one or more networkscontent or messages related to its services to a mobile or othercomputing device of a user. A user may also install softwareapplications on a mobile or other computing device of the user foraccessing a user profile of the user and other data within thesocial-networking system. The social-networking system may generate apersonalized set of content objects to display to a user, such as anewsfeed of aggregated stories of other users connected to the user.

Social-graph analysis views social relationships in terms of networktheory consisting of nodes and edges. Nodes represent the individualactors within the networks, and edges represent the relationshipsbetween the actors. The resulting graph-based structures are often verycomplex. There can be many types of nodes and many types of edges forconnecting nodes. In its simplest form, a social graph is a map of allof the relevant edges between all the nodes being studied.

SUMMARY OF PARTICULAR EMBODIMENTS

In particular embodiments, in response to a text query received from auser, a social-networking system may generate structured queriescomprising query tokens that correspond to identified social-graphelements. By providing suggested structured queries in response to auser's text query, the social-networking system may provide a powerfulway for users of an online social network to search for elementsrepresented in a social graph based on their social-graph attributes andtheir relation to various social-graph elements.

In particular embodiments, the social-networking system may receive anunstructured text query from a user. In response, the social-networkingsystem may access a social graph and then parse the text query toidentify social-graph elements that corresponded to n-grams from thetext query. The social-networking system may then access a grammarmodel, such as a context-free grammar model. The identified social-graphelements may be used as terminal tokens (“query tokens”) in the grammarsof the grammar model. Any grammar that can utilize all of the identifiedquery tokens may be selected. These grammars may be identified by firstgenerating a semantic tree corresponding to the text query, and thenanalyzing a grammar forest to find sub-trees that match the semantictree. The selected grammars may then be used to generatenatural-language structured queries that include query tokensreferencing the identified social-graph elements. The structured queriesmay then be transmitted and displayed to the user, where the user canthen select an appropriate query to search for the desired content.

In particular embodiments, in response to a structured query, thesocial-networking system may generate one or more search resultscorresponding to the structured query. These search results may betransmitted to the querying user as part of a search-results page. Eachsearch result may include one or more snippets, where the snippet may becontextual information about social-graph entity that corresponds to thesearch result. For example, a snippet may be information from theprofile page associated with a node. Each search result may also includeat least one snippet providing social-graph information for the searchresult. These snippets may contain references to the query tokens fromthe structured query used to generate the search result.

In particular embodiments, in response to a structured query, thesocial-networking system may generate one or more query modificationsfor the structured query. Each query modification may include referencesto modified nodes or modified edges from the social graph, which may beused to add or replace query tokens in the structured query. The querymodifications may be displayed on the search-results page, allowing auser to view the search results and then select one or more querymodifications to refine or pivot the structured query and generate newsearch results. After modifying a structured query with a particularquery modification, an appropriate grammar may be used to generate a newnatural-language structured query that includes reference to thesocial-graph elements used in the query modification. Thesocial-networking system may also generate alternative structuredqueries that may be displayed on the search-results page. Thesealternative structured queries include suggested queries, broadeningqueries, and disambiguation queries.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example network environment associated with asocial-networking system.

FIG. 2 illustrates an example social graph.

FIG. 3 illustrates an example webpage of an online social network.

FIGS. 4A-4B illustrate example queries of the social network.

FIG. 5A illustrates an example semantic tree

FIG. 5B illustrates an example grammar forest.

FIG. 6 illustrates an example method for using a context-free grammarmodel to generate natural-language structured search queries.

FIGS. 7A-7G illustrate example search-results pages.

FIG. 8 illustrates an example method for generating search results andsnippets.

FIG. 9 illustrates an example method for modifying structured searchqueries.

FIG. 10 illustrates an example computer system.

DESCRIPTION OF EXAMPLE EMBODIMENTS System Overview

FIG. 1 illustrates an example network environment 100 associated with asocial-networking system. Network environment 100 includes a clientsystem 130, a social-networking system 160, and a third-party system 170connected to each other by a network 110. Although FIG. 1 illustrates aparticular arrangement of client system 130, social-networking system160, third-party system 170, and network 110, this disclosurecontemplates any suitable arrangement of client system 130,social-networking system 160, third-party system 170, and network 110.As an example and not by way of limitation, two or more of client system130, social-networking system 160, and third-party system 170 may beconnected to each other directly, bypassing network 110. As anotherexample, two or more of client system 130, social-networking system 160,and third-party system 170 may be physically or logically co-locatedwith each other in whole or in part. Moreover, although FIG. 1illustrates a particular number of client systems 130, social-networkingsystems 160, third-party systems 170, and networks 110, this disclosurecontemplates any suitable number of client systems 130,social-networking systems 160, third-party systems 170, and networks110. As an example and not by way of limitation, network environment 100may include multiple client system 130, social-networking systems 160,third-party systems 170, and networks 110.

This disclosure contemplates any suitable network 110. As an example andnot by way of limitation, one or more portions of network 110 mayinclude an ad hoc network, an intranet, an extranet, a virtual privatenetwork (VPN), a local area network (LAN), a wireless LAN (WLAN), a widearea network (WAN), a wireless WAN (WWAN), a metropolitan area network(MAN), a portion of the Internet, a portion of the Public SwitchedTelephone Network (PSTN), a cellular telephone network, or a combinationof two or more of these. Network 110 may include one or more networks110.

Links 150 may connect client system 130, social-networking system 160,and third-party system 170 to communication network 110 or to eachother. This disclosure contemplates any suitable links 150. Inparticular embodiments, one or more links 150 include one or morewireline (such as for example Digital Subscriber Line (DSL) or Data OverCable Service Interface Specification (DOCSIS)), wireless (such as forexample Wi-Fi or Worldwide Interoperability for Microwave Access(WiMAX)), or optical (such as for example Synchronous Optical Network(SONET) or Synchronous Digital Hierarchy (SDH)) links. In particularembodiments, one or more links 150 each include an ad hoc network, anintranet, an extranet, a VPN, a LAN, a WLAN, a WAN, a WWAN, a MAN, aportion of the Internet, a portion of the PSTN, a cellulartechnology-based network, a satellite communications technology-basednetwork, another link 150, or a combination of two or more such links150. Links 150 need not necessarily be the same throughout networkenvironment 100. One or more first links 150 may differ in one or morerespects from one or more second links 150.

In particular embodiments, client system 130 may be an electronic deviceincluding hardware, software, or embedded logic components or acombination of two or more such components and capable of carrying outthe appropriate functionalities implemented or supported by clientsystem 130. As an example and not by way of limitation, a client system130 may include a computer system such as a desktop computer, notebookor laptop computer, netbook, a tablet computer, e-book reader, GPSdevice, camera, personal digital assistant (PDA), handheld electronicdevice, cellular telephone, smartphone, other suitable electronicdevice, or any suitable combination thereof. This disclosurecontemplates any suitable client systems 130. A client system 130 mayenable a network user at client system 130 to access network 110. Aclient system 130 may enable its user to communicate with other users atother client systems 130.

In particular embodiments, client system 130 may include a web browser132, such as MICROSOFT INTERNET EXPLORER, GOOGLE CHROME or MOZILLAFIREFOX, and may have one or more add-ons, plug-ins, or otherextensions, such as TOOLBAR or YAHOO TOOLBAR. A user at client system130 may enter a Uniform Resource Locator (URL) or other addressdirecting the web browser 132 to a particular server (such as server162, or a server associated with a third-party system 170), and the webbrowser 132 may generate a Hyper Text Transfer Protocol (HTTP) requestand communicate the HTTP request to server. The server may accept theHTTP request and communicate to client system 130 one or more Hyper TextMarkup Language (HTML) files responsive to the HTTP request. Clientsystem 130 may render a webpage based on the HTML files from the serverfor presentation to the user. This disclosure contemplates any suitablewebpage files. As an example and not by way of limitation, webpages mayrender from HTML files, Extensible Hyper Text Markup Language (XHTML)files, or Extensible Markup Language (XML) files, according toparticular needs. Such pages may also execute scripts such as, forexample and without limitation, those written in JAVASCRIPT, JAVA,MICROSOFT SILVERLIGHT, combinations of markup language and scripts suchas AJAX (Asynchronous JAVASCRIPT and XML), and the like. Herein,reference to a webpage encompasses one or more corresponding webpagefiles (which a browser may use to render the webpage) and vice versa,where appropriate.

In particular embodiments, social-networking system 160 may be anetwork-addressable computing system that can host an online socialnetwork. Social-networking system 160 may generate, store, receive, andtransmit social-networking data, such as, for example, user-profiledata, concept-profile data, social-graph information, or other suitabledata related to the online social network. Social-networking system 160may be accessed by the other components of network environment 100either directly or via network 110. In particular embodiments,social-networking system 160 may include one or more servers 162. Eachserver 162 may be a unitary server or a distributed server spanningmultiple computers or multiple datacenters. Servers 162 may be ofvarious types, such as, for example and without limitation, web server,news server, mail server, message server, advertising server, fileserver, application server, exchange server, database server, proxyserver, another server suitable for performing functions or processesdescribed herein, or any combination thereof. In particular embodiments,each server 162 may include hardware, software, or embedded logiccomponents or a combination of two or more such components for carryingout the appropriate functionalities implemented or supported by server162. In particular embodiments, social-networking system 164 may includeone or more data stores 164. Data stores 164 may be used to storevarious types of information. In particular embodiments, the informationstored in data stores 164 may be organized according to specific datastructures. In particular embodiments, each data store 164 may be arelational database. Particular embodiments may provide interfaces thatenable a client system 130, a social-networking system 160, or athird-party system 170 to manage, retrieve, modify, add, or delete, theinformation stored in data store 164.

In particular embodiments, social-networking system 160 may store one ormore social graphs in one or more data stores 164. In particularembodiments, a social graph may include multiple nodes—which may includemultiple user nodes (each corresponding to a particular user) ormultiple concept nodes (each corresponding to a particular concept)—andmultiple edges connecting the nodes. Social-networking system 160 mayprovide users of the online social network the ability to communicateand interact with other users. In particular embodiments, users may jointhe online social network via social-networking system 160 and then addconnections (i.e., relationships) to a number of other users ofsocial-networking system 160 whom they want to be connected to. Herein,the term “friend” may refer to any other user of social-networkingsystem 160 with whom a user has formed a connection, association, orrelationship via social-networking system 160.

In particular embodiments, social-networking system 160 may provideusers with the ability to take actions on various types of items orobjects, supported by social-networking system 160. As an example andnot by way of limitation, the items and objects may include groups orsocial networks to which users of social-networking system 160 maybelong, events or calendar entries in which a user might be interested,computer-based applications that a user may use, transactions that allowusers to buy or sell items via the service, interactions withadvertisements that a user may perform, or other suitable items orobjects. A user may interact with anything that is capable of beingrepresented in social-networking system 160 or by an external system ofthird-party system 170, which is separate from social-networking system160 and coupled to social-networking system 160 via a network 110.

In particular embodiments, social-networking system 160 may be capableof linking a variety of entities. As an example and not by way oflimitation, social-networking system 160 may enable users to interactwith each other as well as receive content from third-party systems 170or other entities, or to allow users to interact with these entitiesthrough an application programming interfaces (API) or othercommunication channels.

In particular embodiments, a third-party system 170 may include one ormore types of servers, one or more data stores, one or more interfaces,including but not limited to APIs, one or more web services, one or morecontent sources, one or more networks, or any other suitable components,e.g., that servers may communicate with. A third-party system 170 may beoperated by a different entity from an entity operatingsocial-networking system 160. In particular embodiments, however,social-networking system 160 and third-party systems 170 may operate inconjunction with each other to provide social-networking services tousers of social-networking system 160 or third-party systems 170. Inthis sense, social-networking system 160 may provide a platform, orbackbone, which other systems, such as third-party systems 170, may useto provide social-networking services and functionality to users acrossthe Internet.

In particular embodiments, a third-party system 170 may include athird-party content object provider. A third-party content objectprovider may include one or more sources of content objects, which maybe communicated to a client system 130. As an example and not by way oflimitation, content objects may include information regarding things oractivities of interest to the user, such as, for example, movie showtimes, movie reviews, restaurant reviews, restaurant menus, productinformation and reviews, or other suitable information. As anotherexample and not by way of limitation, content objects may includeincentive content objects, such as coupons, discount tickets, giftcertificates, or other suitable incentive objects.

In particular embodiments, social-networking system 160 also includesuser-generated content objects, which may enhance a user's interactionswith social-networking system 160. User-generated content may includeanything a user can add, upload, send, or “post” to social-networkingsystem 160. As an example and not by way of limitation, a usercommunicates posts to social-networking system 160 from a client system130. Posts may include data such as status updates or other textualdata, location information, photos, videos, links, music or othersimilar data or media. Content may also be added to social-networkingsystem 160 by a third-party through a “communication channel,” such as anewsfeed or stream.

In particular embodiments, social-networking system 160 may include avariety of servers, sub-systems, programs, modules, logs, and datastores. In particular embodiments, social-networking system 160 mayinclude one or more of the following: a web server, action logger,API-request server, relevance-and-ranking engine, content-objectclassifier, notification controller, action log,third-party-content-object-exposure log, inference module,authorization/privacy server, search module, ad-targeting module,user-interface module, user-profile store, connection store, third-partycontent store, or location store. Social-networking system 160 may alsoinclude suitable components such as network interfaces, securitymechanisms, load balancers, failover servers,management-and-network-operations consoles, other suitable components,or any suitable combination thereof. In particular embodiments,social-networking system 160 may include one or more user-profile storesfor storing user profiles. A user profile may include, for example,biographic information, demographic information, behavioral information,social information, or other types of descriptive information, such aswork experience, educational history, hobbies or preferences, interests,affinities, or location. Interest information may include interestsrelated to one or more categories. Categories may be general orspecific. As an example and not by way of limitation, if a user “likes”an article about a brand of shoes the category may be the brand, or thegeneral category of “shoes” or “clothing.” A connection store may beused for storing connection information about users. The connectioninformation may indicate users who have similar or common workexperience, group memberships, hobbies, educational history, or are inany way related or share common attributes. The connection informationmay also include user-defined connections between different users andcontent (both internal and external). A web server may be used forlinking social-networking system 160 to one or more client systems 130or one or more third-party system 170 via network 110. The web servermay include a mail server or other messaging functionality for receivingand routing messages between social-networking system 160 and one ormore client systems 130. An API-request server may allow a third-partysystem 170 to access information from social-networking system 160 bycalling one or more APIs. An action logger may be used to receivecommunications from a web server about a user's actions on or offsocial-networking system 160. In conjunction with the action log, athird-party-content-object log may be maintained of user exposures tothird-party-content objects. A notification controller may provideinformation regarding content objects to a client system 130.Information may be pushed to a client system 130 as notifications, orinformation may be pulled from client system 130 responsive to a requestreceived from client system 130. Authorization servers may be used toenforce one or more privacy settings of the users of social-networkingsystem 160. A privacy setting of a user determines how particularinformation associated with a user can be shared. The authorizationserver may allow users to opt in or opt out of having their actionslogged by social-networking system 160 or shared with other systems(e.g., third-party system 170), such as, for example, by settingappropriate privacy settings. Third-party-content-object stores may beused to store content objects received from third parties, such as athird-party system 170. Location stores may be used for storing locationinformation received from client systems 130 associated with users.Ad-pricing modules may combine social information, the current time,location information, or other suitable information to provide relevantadvertisements, in the form of notifications, to a user.

Social Graphs

FIG. 2 illustrates example social graph 200. In particular embodiments,social-networking system 160 may store one or more social graphs 200 inone or more data stores. In particular embodiments, social graph 200 mayinclude multiple nodes—which may include multiple user nodes 202 ormultiple concept nodes 204—and multiple edges 206 connecting the nodes.Example social graph 200 illustrated in FIG. 2 is shown, for didacticpurposes, in a two-dimensional visual map representation. In particularembodiments, a social-networking system 160, client system 130, orthird-party system 170 may access social graph 200 and relatedsocial-graph information for suitable applications. The nodes and edgesof social graph 200 may be stored as data objects, for example, in adata store (such as a social-graph database). Such a data store mayinclude one or more searchable or queryable indexes of nodes or edges ofsocial graph 200.

In particular embodiments, a user node 202 may correspond to a user ofsocial-networking system 160. As an example and not by way oflimitation, a user may be an individual (human user), an entity (e.g.,an enterprise, business, or third-party application), or a group (e.g.,of individuals or entities) that interacts or communicates with or oversocial-networking system 160. In particular embodiments, when a userregisters for an account with social-networking system 160,social-networking system 160 may create a user node 202 corresponding tothe user, and store the user node 202 in one or more data stores. Usersand user nodes 202 described herein may, where appropriate, refer toregistered users and user nodes 202 associated with registered users. Inaddition or as an alternative, users and user nodes 202 described hereinmay, where appropriate, refer to users that have not registered withsocial-networking system 160. In particular embodiments, a user node 202may be associated with information provided by a user or informationgathered by various systems, including social-networking system 160. Asan example and not by way of limitation, a user may provide his or hername, profile picture, contact information, birth date, sex, maritalstatus, family status, employment, education background, preferences,interests, or other demographic information. In particular embodiments,a user node 202 may be associated with one or more data objectscorresponding to information associated with a user. In particularembodiments, a user node 202 may correspond to one or more webpages.

In particular embodiments, a concept node 204 may correspond to aconcept. As an example and not by way of limitation, a concept maycorrespond to a place (such as, for example, a movie theater,restaurant, landmark, or city); a website (such as, for example, awebsite associated with social-network system 160 or a third-partywebsite associated with a web-application server); an entity (such as,for example, a person, business, group, sports team, or celebrity); aresource (such as, for example, an audio file, video file, digitalphoto, text file, structured document, or application) which may belocated within social-networking system 160 or on an external server,such as a web-application server; real or intellectual property (suchas, for example, a sculpture, painting, movie, game, song, idea,photograph, or written work); a game; an activity; an idea or theory;another suitable concept; or two or more such concepts. A concept node204 may be associated with information of a concept provided by a useror information gathered by various systems, including social-networkingsystem 160. As an example and not by way of limitation, information of aconcept may include a name or a title; one or more images (e.g., animage of the cover page of a book); a location (e.g., an address or ageographical location); a website (which may be associated with a URL);contact information (e.g., a phone number or an email address); othersuitable concept information; or any suitable combination of suchinformation. In particular embodiments, a concept node 204 may beassociated with one or more data objects corresponding to informationassociated with concept node 204. In particular embodiments, a conceptnode 204 may correspond to one or more webpages.

In particular embodiments, a node in social graph 200 may represent orbe represented by a webpage (which may be referred to as a “profilepage”). Profile pages may be hosted by or accessible tosocial-networking system 160. Profile pages may also be hosted onthird-party websites associated with a third-party server 170. As anexample and not by way of limitation, a profile page corresponding to aparticular external webpage may be the particular external webpage andthe profile page may correspond to a particular concept node 204.Profile pages may be viewable by all or a selected subset of otherusers. As an example and not by way of limitation, a user node 202 mayhave a corresponding user-profile page in which the corresponding usermay add content, make declarations, or otherwise express himself orherself. As another example and not by way of limitation, a concept node204 may have a corresponding concept-profile page in which one or moreusers may add content, make declarations, or express themselves,particularly in relation to the concept corresponding to concept node204.

In particular embodiments, a concept node 204 may represent athird-party webpage or resource hosted by a third-party system 170. Thethird-party webpage or resource may include, among other elements,content, a selectable or other icon, or other inter-actable object(which may be implemented, for example, in JavaScript, AJAX, or PHPcodes) representing an action or activity. As an example and not by wayof limitation, a third-party webpage may include a selectable icon suchas “like,” “check in,” “eat,” “recommend,” or another suitable action oractivity. A user viewing the third-party webpage may perform an actionby selecting one of the icons (e.g., “eat”), causing a client system 130to transmit to social-networking system 160 a message indicating theuser's action. In response to the message, social-networking system 160may create an edge (e.g., an “eat” edge) between a user node 202corresponding to the user and a concept node 204 corresponding to thethird-party webpage or resource and store edge 206 in one or more datastores.

In particular embodiments, a pair of nodes in social graph 200 may beconnected to each other by one or more edges 206. An edge 206 connectinga pair of nodes may represent a relationship between the pair of nodes.In particular embodiments, an edge 206 may include or represent one ormore data objects or attributes corresponding to the relationshipbetween a pair of nodes. As an example and not by way of limitation, afirst user may indicate that a second user is a “friend” of the firstuser. In response to this indication, social-networking system 160 maytransmit a “friend request” to the second user. If the second userconfirms the “friend request,” social-networking system 160 may createan edge 206 connecting the first user's user node 202 to the seconduser's user node 202 in social graph 200 and store edge 206 associal-graph information in one or more of data stores 24. In theexample of FIG. 2, social graph 200 includes an edge 206 indicating afriend relation between user nodes 202 of user “A” and user “B” and anedge indicating a friend relation between user nodes 202 of user “C” anduser “B.” Although this disclosure describes or illustrates particularedges 206 with particular attributes connecting particular user nodes202, this disclosure contemplates any suitable edges 206 with anysuitable attributes connecting user nodes 202. As an example and not byway of limitation, an edge 206 may represent a friendship, familyrelationship, business or employment relationship, fan relationship,follower relationship, visitor relationship, subscriber relationship,superior/subordinate relationship, reciprocal relationship,non-reciprocal relationship, another suitable type of relationship, ortwo or more such relationships. Moreover, although this disclosuregenerally describes nodes as being connected, this disclosure alsodescribes users or concepts as being connected. Herein, references tousers or concepts being connected may, where appropriate, refer to thenodes corresponding to those users or concepts being connected in socialgraph 200 by one or more edges 206.

In particular embodiments, an edge 206 between a user node 202 and aconcept node 204 may represent a particular action or activity performedby a user associated with user node 202 toward a concept associated witha concept node 204. As an example and not by way of limitation, asillustrated in FIG. 2, a user may “like,” “attended,” “played,”“listened,” “cooked,” “worked at,” or “watched” a concept, each of whichmay correspond to a edge type or subtype. A concept-profile pagecorresponding to a concept node 204 may include, for example, aselectable “check in” icon (such as, for example, a clickable “check in”icon) or a selectable “add to favorites” icon. Similarly, after a userclicks these icons, social-networking system 160 may create a “favorite”edge or a “check in” edge in response to a user's action correspondingto a respective action. As another example and not by way of limitation,a user (user “C”) may listen to a particular song (“Imagine”) using aparticular application (SPOTIFY, which is an online music application).In this case, social-networking system 160 may create a “listened” edge206 and a “used” edge (as illustrated in FIG. 2) between user nodes 202corresponding to the user and concept nodes 204 corresponding to thesong and application to indicate that the user listened to the song andused the application. Moreover, social-networking system 160 may createa “played” edge 206 (as illustrated in FIG. 2) between concept nodes 204corresponding to the song and the application to indicate that theparticular song was played by the particular application. In this case,“played” edge 206 corresponds to an action performed by an externalapplication (SPOTIFY) on an external audio file (the song “Imagine”).Although this disclosure describes particular edges 206 with particularattributes connecting user nodes 202 and concept nodes 204, thisdisclosure contemplates any suitable edges 206 with any suitableattributes connecting user nodes 202 and concept nodes 204. Moreover,although this disclosure describes edges between a user node 202 and aconcept node 204 representing a single relationship, this disclosurecontemplates edges between a user node 202 and a concept node 204representing one or more relationships. As an example and not by way oflimitation, an edge 206 may represent both that a user likes and hasused at a particular concept. Alternatively, another edge 206 mayrepresent each type of relationship (or multiples of a singlerelationship) between a user node 202 and a concept node 204 (asillustrated in FIG. 2 between user node 202 for user “E” and conceptnode 204 for “SPOTIFY”).

In particular embodiments, social-networking system 160 may create anedge 206 between a user node 202 and a concept node 204 in social graph200. As an example and not by way of limitation, a user viewing aconcept-profile page (such as, for example, by using a web browser or aspecial-purpose application hosted by the user's client system 130) mayindicate that he or she likes the concept represented by the conceptnode 204 by clicking or selecting a “Like” icon, which may cause theuser's client system 130 to transmit to social-networking system 160 amessage indicating the user's liking of the concept associated with theconcept-profile page. In response to the message, social-networkingsystem 160 may create an edge 206 between user node 202 associated withthe user and concept node 204, as illustrated by “like” edge 206 betweenthe user and concept node 204. In particular embodiments,social-networking system 160 may store an edge 206 in one or more datastores. In particular embodiments, an edge 206 may be automaticallyformed by social-networking system 160 in response to a particular useraction. As an example and not by way of limitation, if a first useruploads a picture, watches a movie, or listens to a song, an edge 206may be formed between user node 202 corresponding to the first user andconcept nodes 204 corresponding to those concepts. Although thisdisclosure describes forming particular edges 206 in particular manners,this disclosure contemplates forming any suitable edges 206 in anysuitable manner.

Advertising

In particular embodiments, an advertisement may be text (which may beHTML-linked), one or more images (which may be HTML-linked), one or morevideos, audio, one or more ADOBE FLASH files, a suitable combination ofthese, or any other suitable advertisement in any suitable digitalformat presented on one or more webpages, in one or more e-mails, or inconnection with search results requested by a user). In addition or asan alternative, an advertisement may be one or more sponsored stories(e.g. a news-feed or ticker item on social-networking system 160). Asponsored story may be a social action by a user (such as “liking” apage, “liking” or commenting on a post on a page, RSVPing to an eventassociated with a page, voting on a question posted on a page, checkingin to a place, using an application or playing a game, or “liking” orsharing a website) that an advertiser promotes by, for example, havingthe social action presented within a pre-determined area of a profilepage of a user or other page, presented with additional informationassociated with the advertiser, bumped up or otherwise highlightedwithin news feeds or tickers of other users, or otherwise promoted. Theadvertiser may pay to have the social action promoted.

In particular embodiments, an advertisement may be requested for displaywithin social-networking-system webpages, third-party webpages, or otherpages. An advertisement may be displayed in a dedicated portion of apage, such as in a banner area at the top of the page, in a column atthe side of the page, in a GUI of the page, in a pop-up window, in adrop-down menu, in an input field of the page, over the top of contentof the page, or elsewhere with respect to the page. In addition or as analternative, an advertisement may be displayed within an application. Anadvertisement may be displayed within dedicated pages, requiring theuser to interact with or watch the advertisement before the user mayaccess a page or utilize an application. The user may, for example viewthe advertisement through a web browser.

A user may interact with an advertisement in any suitable manner. Theuser may click or otherwise select the advertisement. By selecting theadvertisement, the user may be directed to (or a browser or otherapplication being used by the user) a page associated with theadvertisement. At the page associated with the advertisement, the usermay take additional actions, such as purchasing a product or serviceassociated with the advertisement, receiving information associated withthe advertisement, or subscribing to a newsletter associated with theadvertisement. An advertisement with audio or video may be played byselecting a component of the advertisement (like a “play button”).Alternatively, by selecting the advertisement, the social-networkingsystem 160 may execute or modify a particular action of the user. As anexample and not by way of limitation, advertisements may be includedamong the search results of a search-results page, where sponsoredcontent is promoted over non-sponsored content. As another example andnot by way of limitation, advertisements may be included among suggestedsearch query, where suggested queries that reference the advertiser orits content/products may be promoted over non-sponsored queries.

An advertisement may include social-networking-system functionality thata user may interact with. For example, an advertisement may enable auser to “like” or otherwise endorse the advertisement by selecting anicon or link associated with endorsement. As another example, anadvertisement may enable a user to search (e.g., by executing a query)for content related to the advertiser. Similarly, a user may share theadvertisement with another user (e.g. through social-networking system160) or RSVP (e.g. through social-networking system 160) to an eventassociated with the advertisement. In addition or as an alternative, anadvertisement may include social-networking-system context directed tothe user. For example, an advertisement may display information about afriend of the user within social-networking system 160 who has taken anaction associated with the subject matter of the advertisement.

Typeahead Processes

In particular embodiments, one or more client-side and/or backend(server-side) processes may implement and utilize a “typeahead” featurethat may automatically attempt to match social-graph elements (e.g.,user nodes 202, concept nodes 204, or edges 206) to informationcurrently being entered by a user in an input form rendered inconjunction with a requested webpage (such as, for example, auser-profile page, a concept-profile page, a search-results webpage, oranother suitable page of the online social network), which may be hostedby or accessible in the social-networking system 160. In particularembodiments, as a user is entering text to make a declaration, thetypeahead feature may attempt to match the string of textual charactersbeing entered in the declaration to strings of characters (e.g., names,descriptions) corresponding to user, concepts, or edges and theircorresponding elements in the social graph 200. In particularembodiments, when a match is found, the typeahead feature mayautomatically populate the form with a reference to the social-graphelement (such as, for example, the node name/type, node ID, edgename/type, edge ID, or another suitable reference or identifier) of theexisting social-graph element.

In particular embodiments, as a user types or otherwise enters text intoa form used to add content or make declarations in various sections ofthe user's profile page, home page, or other page, the typeahead processmay work in conjunction with one or more frontend (client-side) and/orbackend (server-side) typeahead processes (hereinafter referred tosimply as “typeahead process”) executing at (or within) thesocial-networking system 160 (e.g., within servers 162), tointeractively and virtually instantaneously (as appearing to the user)attempt to auto-populate the form with a term or terms corresponding tonames of existing social-graph elements, or terms associated withexisting social-graph elements, determined to be the most relevant orbest match to the characters of text entered by the user as the userenters the characters of text. Utilizing the social-graph information ina social-graph database or information extracted and indexed from thesocial-graph database, including information associated with nodes andedges, the typeahead processes, in conjunction with the information fromthe social-graph database, as well as potentially in conjunction withvarious others processes, applications, or databases located within orexecuting within social-networking system 160, may be able to predict auser's intended declaration with a high degree of precision. However,the social-networking system 160 can also provides user's with thefreedom to enter essentially any declaration they wish, enabling usersto express themselves freely.

In particular embodiments, as a user enters text characters into a formbox or other field, the typeahead processes may attempt to identifyexisting social-graph elements (e.g., user nodes 202, concept nodes 204,or edges 206) that match the string of characters entered in the user'sdeclaration as the user is entering the characters. In particularembodiments, as the user enters characters into a form box, thetypeahead process may read the string of entered textual characters. Aseach keystroke is made, the frontend-typeahead process may transmit theentered character string as a request (or call) to the backend-typeaheadprocess executing within social-networking system 160. In particularembodiments, the typeahead processes may communicate via AJAX(Asynchronous JavaScript and XML) or other suitable techniques, andparticularly, asynchronous techniques. In particular embodiments, therequest may be, or comprise, an XMLHTTPRequest (XHR) enabling quick anddynamic sending and fetching of results. In particular embodiments, thetypeahead process may also transmit before, after, or with the request asection identifier (section ID) that identifies the particular sectionof the particular page in which the user is making the declaration. Inparticular embodiments, a user ID parameter may also be sent, but thismay be unnecessary in some embodiments, as the user may already be“known” based on the user having logged into (or otherwise beenauthenticated by) the social-networking system 160.

In particular embodiments, the typeahead process may use one or morematching algorithms to attempt to identify matching social-graphelements. In particular embodiments, when a match or matches are found,the typeahead process may transmit a response (which may utilize AJAX orother suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) or descriptions of thematching social-graph elements as well as, potentially, other metadataassociated with the matching social-graph elements. As an example andnot by way of limitation, if a user entering the characters “pok” into aquery field, the typeahead process may display a drop-down menu thatdisplays names of matching existing profile pages and respective usernodes 202 or concept nodes 204, such as a profile page named or devotedto “poker” or “pokemon”, which the user can then click on or otherwiseselect thereby confirming the desire to declare the matched user orconcept name corresponding to the selected node. As another example andnot by way of limitation, upon clicking “poker,” the typeahead processmay auto-populate, or causes the web browser 132 to auto-populate, thequery field with the declaration “poker”. In particular embodiments, thetypeahead process may simply auto-populate the field with the name orother identifier of the top-ranked match rather than display a drop-downmenu. The user may then confirm the auto-populated declaration simply bykeying “enter” on his or her keyboard or by clicking on theauto-populated declaration.

More information on typeahead processes may be found in U.S. patentapplication Ser. No. 12/763,162, filed 19 Apr. 2010, and U.S. patentapplication Ser. No. 13/556,072, filed 23 Jul. 2012, which areincorporated by reference.

Structured Search Queries

FIG. 3 illustrates an example webpage of an online social network. Inparticular embodiments, a user may submit a query to the social-networksystem 160 by inputting text into query field 350. A user of an onlinesocial network may search for information relating to a specific subjectmatter (e.g., users, concepts, external content or resource) byproviding a short phrase describing the subject matter, often referredto as a “search query,” to a search engine. The query may be anunstructured text query and may comprise one or more text strings (whichmay include one or more n-grams). In general, a user may input anycharacter string into query field 350 to search for content on thesocial-networking system 160 that matches the text query. Thesocial-networking system 160 may then search a data store 164 (or, inparticular, a social-graph database) to identify content matching thequery. The search engine may conduct a search based on the query phraseusing various search algorithms and generate search results thatidentify resources or content (e.g., user-profile pages, content-profilepages, or external resources) that are most likely to be related to thesearch query. To conduct a search, a user may input or transmit a searchquery to the search engine. In response, the search engine may identifyone or more resources that are likely to be related to the search query,each of which may individually be referred to as a “search result,” orcollectively be referred to as the “search results” corresponding to thesearch query. The identified content may include, for example,social-graph elements (i.e., user nodes 202, concept nodes 204, edges206), profile pages, external webpages, or any combination thereof. Thesocial-networking system 160 may then generate a search-results webpagewith search results corresponding to the identified content and transmitthe search-results webpage to the user. The search results may bepresented to the user, often in the form of a list of links on thesearch-results webpage, each link being associated with a differentwebpage that contains some of the identified resources or content. Inparticular embodiments, each link in the search results may be in theform of a Uniform Resource Locator (URL) that specifies where thecorresponding webpage is located and the mechanism for retrieving it.The social-networking system 160 may then transmit the search-resultswebpage to the web browser 132 on the user's client system 130. The usermay then click on the URL links or otherwise select the content from thesearch-results webpage to access the content from the social-networkingsystem 160 or from an external system (such as, for example, athird-party system 170), as appropriate. The resources may be ranked andpresented to the user according to their relative degrees of relevanceto the search query. The search results may also be ranked and presentedto the user according to their relative degree of relevance to the user.In other words, the search results may be personalized for the queryinguser based on, for example, social-graph information, user information,search or browsing history of the user, or other suitable informationrelated to the user. In particular embodiments, ranking of the resourcesmay be determined by a ranking algorithm implemented by the searchengine. As an example and not by way of limitation, resources that aremore relevant to the search query or to the user may be ranked higherthan the resources that are less relevant to the search query or theuser. In particular embodiments, the search engine may limit its searchto resources and content on the online social network. However, inparticular embodiments, the search engine may also search for resourcesor contents on other sources, such as a third-party system 170, theinternet or World Wide Web, or other suitable sources. Although thisdisclosure describes querying the social-networking system 160 in aparticular manner, this disclosure contemplates querying thesocial-networking system 160 in any suitable manner.

In particular embodiments, the typeahead processes described herein maybe applied to search queries entered by a user. As an example and not byway of limitation, as a user enters text characters into a search field,a typeahead process may attempt to identify one or more user nodes 202,concept nodes 204, or edges 206 that match the string of charactersentered search field as the user is entering the characters. As thetypeahead process receives requests or calls including a string orn-gram from the text query, the typeahead process may perform or causesto be performed a search to identify existing social-graph elements(i.e., user nodes 202, concept nodes 204, edges 206) having respectivenames, types, categories, or other identifiers matching the enteredtext. The typeahead process may use one or more matching algorithms toattempt to identify matching nodes or edges. When a match or matches arefound, the typeahead process may transmit a response to the user'sclient system 130 that may include, for example, the names (namestrings) of the matching nodes as well as, potentially, other metadataassociated with the matching nodes. The typeahead process may thendisplay a drop-down menu 300 that displays names of matching existingprofile pages and respective user nodes 202 or concept nodes 204, anddisplays names of matching edges 206 that may connect to the matchinguser nodes 202 or concept nodes 204, which the user can then click on orotherwise select thereby confirming the desire to search for the matcheduser or concept name corresponding to the selected node, or to searchfor users or concepts connected to the matched users or concepts by thematching edges. Alternatively, the typeahead process may simplyauto-populate the form with the name or other identifier of thetop-ranked match rather than display a drop-down menu 300. The user maythen confirm the auto-populated declaration simply by keying “enter” ona keyboard or by clicking on the auto-populated declaration. Upon userconfirmation of the matching nodes and edges, the typeahead process maytransmit a request that informs the social-networking system 160 of theuser's confirmation of a query containing the matching social-graphelements. In response to the request transmitted, the social-networkingsystem 160 may automatically (or alternately based on an instruction inthe request) call or otherwise search a social-graph database for thematching social-graph elements, or for social-graph elements connectedto the matching social-graph elements as appropriate. Although thisdisclosure describes applying the typeahead processes to search queriesin a particular manner, this disclosure contemplates applying thetypeahead processes to search queries in any suitable manner.

In connection with search queries and search results, particularembodiments may utilize one or more systems, components, elements,functions, methods, operations, or steps disclosed in U.S. patentapplication Ser. No. 11/503,093, filed 11 Aug. 2006, U.S. patentapplication Ser. No. 12/977,027, filed 22 Dec. 2010, and U.S. patentapplication Ser. No. 12/978,265, filed 23 Dec. 2010, which areincorporated by reference.

Natural-Language Rendering of Structured Search Queries

FIGS. 4A-4B illustrate example queries of the social network. Inparticular embodiments, in response to a text query received from afirst user (i.e., the querying user), the social-networking system 160may generate one or more structured queries rendered in anatural-language syntax, where each structured query includes querytokens that correspond to one or more identified social-graph elements.FIGS. 4A-4B illustrate various example text queries in query field 350and various structured queries generated in response in drop-down menus300. By providing suggested structured queries in response to a user'stext query, the social-networking system 160 may provide a powerful wayfor users of the online social network to search for elementsrepresented in the social graph 200 based on their social-graphattributes and their relation to various social-graph elements.Structured queries may allow a querying user to search for content thatis connected to particular users or concepts in the social graph 200 byparticular edge types. As an example and not by way of limitation, thesocial-networking system 160 may receive an unstructured text query froma first user. In response, the social-networking system 160 (via, forexample, a server-side element detection process) may access the socialgraph 200 and then parse the text query to identify social-graphelements that corresponded to n-grams from the text query. Thesocial-networking system 160 may then access a grammar model, such as acontext-free grammar model, which includes a plurality of grammars.These grammars may be visualized as a grammar forest that is organizedas an ordered tree with a plurality of non-terminal and terminal tokens.The identified social-graph elements may be used as terminal tokens(“query tokens”) in the grammars. Once these terminal tokens have beenidentified (for example, by using a semantic tree that corresponds tothe text query from the user), the social-networking system 160 maytraverse the grammar forest to identify intersecting non-terminal nodes.Each grammar represented by one of these intersecting non-terminal nodesmay then be selected. The selected grammars may then be used to generateone or more structured queries that include the query tokens referencingthe identified social-graph elements. These structured queries may bebased on strings generated by the grammars, such that they are renderedwith references to the appropriate social-graph elements using anatural-language syntax. The structured queries may be transmitted tothe first user and displayed in a drop-down menu 300 (via, for example,a client-side typeahead process), where the first user can then selectan appropriate query to search for the desired content. Some of theadvantages of using the structured queries described herein includefinding users of the online social network based upon limitedinformation, bringing together virtual indexes of content from theonline social network based on the relation of that content to varioussocial-graph elements, or finding content related to you and/or yourfriends. By using this process, the output of the natural-languagerendering process may be efficiently parsed, for example, to generatemodified or alternative structured queries. Furthermore, since the rulesused by this process are derived from the grammar model, anymodification to the rules of the grammar model can be immediatelyreflected in the rendering process. Although this disclosure describesand FIGS. 4A-4B illustrate generating particular structured queries in aparticular manner, this disclosure contemplates generating any suitablestructured queries in any suitable manner.

In particular embodiments, the social-networking system 160 may receivefrom a querying/first user (corresponding to a first user node 202) anunstructured text query. As an example and not by way of limitation, afirst user may want to search for other users who: (1) are first-degreefriends of the first user; and (2) are associated with StanfordUniversity (i.e., the user nodes 202 are connected by an edge 206 to theconcept node 204 corresponding to the school “Stanford”). The first usermay then enter a text query “friends stanford” into query field 350, asillustrated in FIGS. 4A-4B. As the first user enters this text queryinto query field 350, the social-networking system 160 may providevarious suggested structured queries, as illustrated in drop-down menus300. As used herein, an unstructured text query refers to a simple textstring inputted by a user. The text query may, of course, be structuredwith respect to standard language/grammar rules (e.g. English languagegrammar). However, the text query will ordinarily be unstructured withrespect to social-graph elements. In other words, a simple text querywill not ordinarily include embedded references to particularsocial-graph elements. Thus, as used herein, a structured query refersto a query that contains references to particular social-graph elements,allowing the search engine to search based on the identified elements.Furthermore, the text query may be unstructured with respect to formalquery syntax. In other words, a simple text query will not necessarilybe in the format of a query command that is directly executable by asearch engine. Although this disclosure describes receiving particularqueries in a particular manner, this disclosure contemplates receivingany suitable queries in any suitable manner.

In particular embodiments, social-networking system 160 may parse theunstructured text query (also simply referred to as a search query)received from the first user (i.e., the querying user) to identify oneor more n-grams. In general, an n-gram is a contiguous sequence of nitems from a given sequence of text or speech. The items may becharacters, phonemes, syllables, letters, words, base pairs, prefixes,or other identifiable items from the sequence of text or speech. Then-gram may comprise one or more characters of text (letters, numbers,punctuation, etc.) entered by the querying user. An n-gram of size onecan be referred to as a “unigram,” of size two can be referred to as a“bigram” or “digram,” of size three can be referred to as a “trigram,”and so on. Each n-gram may include one or more parts from the text queryreceived from the querying user. In particular embodiments, each n-grammay comprise a character string (e.g., one or more characters of text)entered by the first user. As an example and not by way of limitation,the social-networking system 160 may parse the text query “friendsstanford” to identify the following n-grams: friends; stanford; friendsstanford. As another example and not by way of limitation, thesocial-networking system 160 may parse the text query “friends in paloalto” to identify the following n-grams: friends; in; palo; alto;friends in; in palo; palo alto; friend in palo; in palo also; friends inpalo alto. In particular embodiments, each n-gram may comprise acontiguous sequence of n items from the text query. Although thisdisclosure describes parsing particular queries in a particular manner,this disclosure contemplates parsing any suitable queries in anysuitable manner.

In particular embodiments, social-networking system 160 may determine orcalculate, for each n-gram identified in the text query, a score thatthe n-gram corresponds to a social-graph element. The score may be, forexample, a confidence score, a probability, a quality, a ranking,another suitable type of score, or any combination thereof. As anexample and not by way of limitation, the social-networking system 160may determine a probability score (also referred to simply as a“probability”) that the n-gram corresponds to a social-graph element,such as a user node 202, a concept node 204, or an edge 206 of socialgraph 200. The probability score may indicate the level of similarity orrelevance between the n-gram and a particular social-graph element.There may be many different ways to calculate the probability. Thepresent disclosure contemplates any suitable method to calculate aprobability score for an n-gram identified in a search query. Inparticular embodiments, the social-networking system 160 may determine aprobability, p, that an n-gram corresponds to a particular social-graphelement. The probability, p, may be calculated as the probability ofcorresponding to a particular social-graph element, k, given aparticular search query, X. In other words, the probability may becalculated as p=(k|X). As an example and not by way of limitation, aprobability that an n-gram corresponds to a social-graph element maycalculated as an probability score denoted as p_(i,j,k). The input maybe a text query X=(x₁, x₂, . . . , x_(N)), and a set of classes. Foreach (i:j) and a class k, the social-networking system 160 may computep_(i,j,k)=p(class(x_(i:j))=k|X). As an example and not by way oflimitation, the n-gram “stanford” could be scored with respect to thefollowing social-graph elements as follows: school “StanfordUniversity”=0.7; location “Stanford, Calif.”=0.2; user “AllenStanford”=0.1. As another example and not by way of limitation, then-gram “friends” could be scored with respect to the followingsocial-graph elements as follows: user “friends”=0.9; television show“Friends”=0.1. In particular embodiments, the social-networking system160 may user a forward-backward algorithm to determine the probabilitythat a particular n-gram corresponds to a particular social-graphelement. For a given n-gram within a text query, the social-networkingsystem 160 may use both the preceding and succeeding n-grams todetermine which particular social-graph elements correspond to the givenn-gram. In particular embodiments, the identified social-graph elementsmay be used to generate a query command that is executable by a searchengine. The query command may be a structured semantic query withdefined functions that accept specific arguments. As an example and notby way of limitation, the text query “friend me mark” could be parsed toform the query command: intersect(friend(me), friend(Mark)). In otherwords, the query is looking for nodes in the social graph that intersectthe querying user (“me”) and the user “Mark” (i.e., those user nodes 202that are connected to both the user node 202 of the querying user by afriend-type edge 206 and the user node 202 for the user “Mark” by afriend-type edge 206). Although this disclosure describes determiningwhether n-grams correspond to social-graph elements in a particularmanner, this disclosure contemplates determining whether n-gramscorrespond to social-graph elements in any suitable manner. Moreover,although this disclosure describes determining whether an n-gramcorresponds to a social-graph element using a particular type of score,this disclosure contemplates determining whether an n-gram correspondsto a social-graph element using any suitable type of score.

In particular embodiments, social-networking system 160 may identify oneor more edges 206 having a probability greater than an edge-thresholdprobability. Each of the identified edges 206 may correspond to at leastone of the n-grams. As an example and not by way of limitation, then-gram may only be identified as corresponding to an edge, k, ifp_(i,j,k)>p_(edge-threshold). Furthermore, each of the identified edges206 may be connected to at least one of the identified nodes. In otherwords, the social-networking system 160 may only identify edges 206 oredge-types that are connected to user nodes 202 or concept nodes 204that have previously been identified as corresponding to a particularn-gram. Edges 206 or edge-types that are not connected to any previouslyidentified node are typically unlikely to correspond to a particularn-gram in a search query. By filtering out or ignoring these edges 206and edge-types, the social-networking system 160 may more efficientlysearch the social graph 200 for relevant social-graph elements. As anexample and not by way of limitation, referencing FIG. 2, for a textquery containing “went to Stanford,” where an identified concept node204 is the school “Stanford,” the social-networking system 160 mayidentify the edges 206 corresponding to “worked at” and the edges 206corresponding to “attended,” both of which are connected to the conceptnode 204 for “Stanford.” Thus, the n-gram “went to” may be identified ascorresponding to these edges 206. However, for the same text query, thesocial-networking system 160 may not identify the edges 206corresponding to “like” or “fan” in the social graph 200 because the“Stanford” node does not have any such edges connected to it. Althoughthis disclosure describes identifying edges 206 that correspond ton-grams in a particular manner, this disclosure contemplates identifyingedges 206 that correspond to n-grams in any suitable manner.

In particular embodiments, social-networking system 160 may identify oneor more user nodes 202 or concept nodes 204 having a probability greaterthan a node-threshold probability. Each of the identified nodes maycorrespond to at least one of the n-grams. As an example and not by wayof limitation, the n-gram may only be identified as corresponding to anode, k, if p_(i,j,k)>p_(node-threshold). Furthermore, each of theidentified user nodes 202 or concept nodes 204 may be connected to atleast one of the identified edges 206. In other words, thesocial-networking system 160 may only identify nodes or nodes-types thatare connected to edges 206 that have previously been identified ascorresponding to a particular n-gram. Nodes or node-types that are notconnected to any previously identified edges 206 are typically unlikelyto correspond to a particular n-gram in a search query. By filtering outor ignoring these nodes and node-types, the social-networking system 160may more efficiently search the social graph 200 for relevantsocial-graph elements. As an example and not by way of limitation, for atext query containing “worked at Apple,” where an identified edge 206 is“worked at,” the social-networking system 160 may identify the conceptnode 204 corresponding to the company APPLE, INC., which may havemultiple edges 206 of “worked at” connected to it. However, for the sametext query, the social-networking system 160 may not identify theconcept node 204 corresponding to the fruit-type “apple,” which may havemultiple “like” or “fan” edges connected to it, but no “worked at” edgeconnections. In particular embodiments, the node-threshold probabilitymay differ for user nodes 202 and concept nodes 204, and may differ evenamong these nodes (e.g., some concept nodes 204 may have differentnode-threshold probabilities than other concept nodes 204). As anexample and not by way of limitation, an n-gram may be identified ascorresponding to a user node 302, k_(user), ifp_(i,j,k)>p_(user-node-threshold), while an n-gram may be identified ascorresponding to a concept node 304, k_(concept) ifp_(i,j,k)>p_(concept-node-threshold). In particular embodiments, thesocial-networking system 160 may only identify nodes that are within athreshold degree of separation of the user node 202 corresponding to thefirst user (i.e., the querying user). The threshold degree of separationmay be, for example, one, two, three, or all. Although this disclosuredescribes identifying nodes that correspond to n-grams in a particularmanner, this disclosure contemplates identifying nodes that correspondto n-grams in any suitable manner.

In particular embodiments, the social-networking system 160 may access acontext-free grammar model comprising a plurality of grammars. Eachgrammar of the grammar model may comprise one or more non-terminaltokens (or “non-terminal symbols”) and one or more terminal tokens (or“terminal symbols”/“query tokens”), where particular non-terminal tokensmay be replaced by terminal tokens. A grammar model is a set offormation rules for strings in a formal language. In particularembodiments, the plurality of grammars may be visualized as a grammarforest organized as an ordered tree, with the internal nodescorresponding to non-terminal tokens and the leaf nodes corresponding toterminal tokens. Each grammar may be represented as a sub-tree withinthe grammar forest, where the grammars are adjoining each other vianon-terminal tokens. Thus, two or more grammars may be a sub-forestwithin the grammar forest. Although this disclosure describes accessingparticular grammars, this disclosure contemplates any suitable grammars.

In particular embodiments, the social-networking system 160 may generateone or more strings using one or more grammars. To generate a string inthe language, one begins with a string consisting of only a single startsymbol. The production rules are then applied in any order, until astring that contains neither the start symbol nor designatednon-terminal symbols is produced. In a context-free grammar, theproduction of each non-terminal symbol of the grammar is independent ofwhat is produced by other non-terminal symbols of the grammar. Thenon-terminal symbols may be replaced with terminal symbols (i.e.,terminal tokens or query tokens). Some of the query tokens maycorrespond to identified nodes or identified edges, as describedpreviously. A string generated by the grammar may then be used as thebasis for a structured query containing references to the identifiednodes or identified edges. The string generated by the grammar may berendered in a natural-language syntax, such that a structured querybased on the string is also rendered in natural language. A context-freegrammar is a grammar in which the left-hand side of each production ruleconsists of only a single non-terminal symbol. A probabilisticcontext-free grammar is a tuple (Σ, N, S, P), where the disjoint sets Σand N specify the terminal and non-terminal symbols, respectively, withSεN being the start symbol. P is the set of productions, which take theform E→ξ(p), with EεN, ξε(Σ∪N)⁺, and p=Pr(E→ξ), the probability that Ewill be expanded into the string ξ. The sum of probabilities p over allexpansions of a given non-terminal E must be one. Although thisdisclosure describes generating strings in a particular manner, thisdisclosure contemplates generating strings in any suitable manner.

In particular embodiments, the social-networking system 160 may identifyone or more query tokens corresponding to the previously identifiednodes and edges. In other words, if an identified node or identifiededge may be used as a query token in a particular grammar, that querytoken may be identified by the social-networking system 160. As anexample and not by way of limitation, an example grammar may be:[user][user-filter][school]. The non-terminal symbols [user],[user-filter], and [school] could then be determined based n-grams inthe received text query. For the text query “friends stanford”, thisquery could be parsed by using the grammar as, for example,“[friends][who go to][Stanford University]” or “[friends][who workat][Stanford University]”. As another example and not by way oflimitation, an example grammar may be [user][user-filter][location]. Forthe text query “friends stanford”, this query could be parsed by usingthe grammar as, for example, “[friends][who live in][Stanford, Calif.]”.In both the example cases above, if the n-grams of the received textquery could be used as query tokens, then these query tokens may beidentified by the social-networking system 160. Although this disclosuredescribes identifying particular query tokens in a particular manner,this disclosure contemplates identifying any suitable query tokens inany suitable manner.

In particular embodiments, the social-networking system 160 may selectone or more grammars having at least one query token corresponding toeach of the previously identified nodes and edges. Only particulargrammars may be used depending on the n-grams identified in the textquery. So the terminal tokens of all available grammars should beexamined to find those that match the identified n-grams from the textquery. In other words, if a particular grammar can use all of theidentified nodes and edges as query tokens, that grammar may be selectedby the social-networking system 160 as a possible grammar to use forgenerating a structured query. This is effectively a type of bottom-upparsing, where the possible query tokens are used to determine theapplicable grammar to apply to the query. As an example and not by wayof limitation, for the text query “friends stanford”, thesocial-networking system may identify the query tokens of [friends] and[Stanford University]. Terminal tokens of the grammars from the grammarmodel may be identified, as previously discussed. Any grammar that isable to use both the [friends] and the [Stanford University] tokens maythen be selected. For example, the grammar [user][user-filter][school]may be selected because this grammar could use the [friends] and the[Stanford University] tokens as query tokens, such as by forming thestrings “friends who go to Stanford University” or “friends who work atStanford University”. Thus, if the n-grams of the received text querycould be used as query tokens in the grammars, then these grammars maybe selected by the social-networking system 160. Similarly, if thereceived text query comprises n-grams that could not be used as querytokens in the grammar, that grammar may not be selected. Although thisdisclosure describes selecting particular grammars in a particularmanner, this disclosure contemplates selecting any suitable grammars inany suitable manner.

In particular embodiments, the social-networking system 160 may selectone or more grammars by analyzing a grammar forest formed by a pluralityof grammars. The grammar forest may be organized as an ordered treecomprising a plurality of non-terminal tokens and a plurality ofterminal tokens. Each grammar may be represented as a sub-tree withinthe grammar forest, and each sub-tree may adjoin other sub-trees via oneor more additional non-terminal tokens. As an example and not by way oflimitation, the social-networking system 160 may start by identifyingall the terminal tokens (i.e., query tokens) in the grammar forest thatcorrespond to identified nodes and edges corresponding to portions of atext query. Once these query tokens in the grammar forest have beenidentified, the social-networking system 160 may then traverse thegrammar forest up from each of these query tokens to identify one ormore intersecting non-terminal tokens. Once a non-terminal token hasbeen identified where paths from all the query tokens intersect, thatintersecting non-terminal token may be selected, and the one or moregrammars adjoined to that intersecting non-terminal token in the grammarforest may then be selected. Although this disclosure describesselecting grammars in a particular manner, this disclosure contemplatesselecting grammars in any suitable manner.

FIG. 5A illustrates an example semantic tree. In particular embodiments,the social-networking system 160 may generate a semantic treecorresponding to the text query from the querying user. The semantictree may include each identified query token that corresponds to apreviously identified node or edge, and may also include an intersecttoken. The semantic tree may also include non-terminal tokens asappropriate connecting the query tokens to the intersect token. As anexample and not by way of limitation, the text query “friends stanford”may be parsed into the query command: intersect(school(StanfordUniversity), friends(me)). In other words, the query is looking fornodes in the social graph that intersect both friends of the queryinguser (“me”) (i.e., those user nodes 202 that are connected to the usernode 202 of the querying user by a friend-type edge 206) and the conceptnode 204 for Stanford University. This may be represented as thesemantic tree illustrated in FIG. 5A, which includes the terminal tokensfor the querying user [me], and the school [Stanford], a non-terminaltoken for [friends of [user]], and an intersect token. In particularembodiments, each token in the tree may be labeled in the order it willbe processed. For example, the semantic tree illustrated in FIG. 5A hastokens labeled using a postfix notation, with the token for [Stanford]labeled as (0,0), the token for [me] labeled as (1,1), the [friends of[user]] token labeled (2), and the intersect token labeled (3). Althoughthis disclosure describes generating particular semantic trees in aparticular manner, this disclosure contemplates generating any suitablesemantic trees in any suitable manner.

FIG. 5B illustrates an example grammar forest. In particularembodiments, the social-networking system 160 may analyze a grammarforest comprising a plurality of grammars to identify one or more setsof non-terminal tokens and query tokens that substantially match asemantic tree corresponding to a query, where each set has anon-terminal token corresponding to the intersect token of the semantictree. The social-networking system 160 may then select one or more ofthe grammars in the grammar forest adjoining the non-terminal tokencorresponding to the intersect token. Each selected intersectingnon-terminal token from the grammar forest may then be labeled as a[start] token for a grammar. As an example and not by way of limitation,the following algorithm may be used to traverse the grammar forest toidentify an intersecting token:

-   -   for each terminal token (i,i) in a semantic tree, label each        matching terminal token in the grammar forest (i,i).    -   for i=0 to size(semantic tree−1):        -   for j=i to 0:            -   expand all tokens labeled (i,j).    -   expand (i,j):        -   for all tokens in the grammar forest:            -   if token has a rule with 1 argument that grows sub-tree                to (i′,j′), then label token as (i′,j′);            -   if token has a rule with more than 1 argument that might                grow the sub-tree, label token as “waiting”;            -   if token is labeled “waiting”, and now can grow sub-tree                to (i′,j′), then label token as (i′,j′).                Thus, for example, in the example illustrated in FIG.                5B, all terminal tokens that match terminal tokens (0,0)                and (1,1) from the semantic tree illustrated in FIG. 5A                will be labeled as (0,0) and (1,1), respectively. Then,                from each valid token in the grammar forest, the                social-networking system 160 may traverse to parent                tokens to see if a sub-tree can be formed that matches                the semantic tree. If the parent non-terminal token has                a matching semantic, that non-terminal token may be                labeled using the same label as the corresponding token                from the semantic tree. In the example illustrated in                FIG. 5B, as the grammar forest is traversed from one of                the tokens labeled (1,1), once a non-terminal token                matching the semantic [friends of [user]] is found, that                token may be labeled (2), so it matches the semantic                tree. A parent of this token may then be labeled as                “waiting” since it is a potential intersect token.                However, if the traverse cannot find any parent tokens                that match the semantic of the semantic tree, then that                particular traverse may be terminated. Once one branch                of the traverse has reached a potential intersect token,                that token may be labeled as “waiting”, while the                algorithm proceeds with traverses from other valid                terminal tokens (e.g., the traverse from terminal tokens                labeled (0,0)). Alternatively, if a traverse finds a                token that has already been labeled as “waiting,” that                token may be identified as an intersect token and                labeled (3). Each token labeled (3) may then be selected                as a grammar, which may be used to generate a                natural-language string for a structured query. The                algorithm will attempt to find the lowest-cost                multi-path in the grammar forest that leads to an                intersect token, and the intersect token corresponding                to this lowest-cost multi-path may be preferentially                selected over other intersect tokens (if any). Although                this disclosure describes analyzing particular grammar                forests in a particular manner, this disclosure                contemplates analyzing any suitable grammar forests in                any suitable manner.

In particular embodiments, the social-networking system 160 maydetermine a score for each selected grammar. The score may be, forexample, a confidence score, a probability, a quality, a ranking,another suitable type of score, or any combination thereof. The scoremay be based on the individual scores or probabilities associated withthe query tokens used in the selected grammar. A grammar may have ahigher relative score if it uses query tokens with relatively higherindividual scores. As an example and not by way of limitation,continuing with the prior examples, the n-gram “stanford” could bescored with respect to the following social-graph elements as follows:school “Stanford University”=0.7; location “Stanford, Calif.”=0.2; user“Allen Stanford”=0.1. The n-gram “friends” could be scored with respectto the following social-graph elements as follows: user “friends”=0.9;television show “Friends”=0.1. Thus, the grammar[user][user-filter][school] may have a relatively high score if it usesthe query tokens for the user “friends” and the school “StanfordUniversity” (generating, for example, the string “friends who go toStanford University”), both of which have relatively high individualscores. In contrast, the grammar [user][user-filter][user] may haverelatively low score if it uses the query tokens for the user “friends”and the user “Allen Stanford” (generating, for example, the string“friends of Allen Stanford”), since the latter query token has arelatively low individual score. In particular embodiments, thesocial-networking system 160 may determine a score for a selectedgrammar based on the lengths of the paths traversed in order to identifythe intersect token corresponding to the selected grammar. Grammars withlower-cost multi-paths (i.e., shorter paths) may be scored more highlythan grammars with high-cost multi-paths (i.e., longer paths). Inparticular embodiments, the social-networking system 160 may determine ascore for a selected grammar based on advertising sponsorship. Anadvertiser (such as, for example, the user or administrator of aparticular profile page corresponding to a particular node) may sponsora particular node such that a grammar that includes a query tokenreferencing that sponsored node may be scored more highly. Although thisdisclosure describes determining particular scores for particulargrammars in a particular manner, this disclosure contemplatesdetermining any suitable scores for any suitable grammars in anysuitable manner.

In particular embodiments, the social-networking system 160 maydetermine the score for a selected grammar based on the relevance of thesocial-graph elements corresponding to the query tokens of the grammarto the querying user (i.e., the first user, corresponding to a firstuser node 202). User nodes 202 and concept nodes 204 that are connectedto the first user node 202 directly by an edge 206 may be consideredrelevant to the first user. Thus, grammars comprising query tokenscorresponding to these relevant nodes and edges may be considered morerelevant to the querying user. As an example and not by way oflimitation, a concept node 204 connected by an edge 206 to a first usernode 202 may be considered relevant to the first user node 202. As usedherein, when referencing a social graph 200 the term “connected” means apath exists within the social graph 200 between two nodes, wherein thepath may comprise one or more edges 206 and zero or more intermediarynodes. In particular embodiments, nodes that are connected to the firstuser node 202 via one or more intervening nodes (and therefore two ormore edges 206) may also be considered relevant to the first user.Furthermore, in particular embodiments, the closer the second node is tothe first user node, the more relevant the second node may be consideredto the first user node. That is, the fewer edges 206 separating thefirst user node 202 from a particular user node 202 or concept node 204(i.e., the fewer degrees of separation), the more relevant that usernode 202 or concept node 204 may be considered to the first user. As anexample and not by way of limitation, as illustrated in FIG. 2, theconcept node 204 corresponding to the school “Stanford” is connected tothe user node 202 corresponding to User “C,” and thus the concept“Stanford” may be considered relevant to User “C.” As another exampleand not by way of limitation, the user node 202 corresponding to User“A” is connected to the user node 202 corresponding to User “C” via oneintermediate node and two edges 206 (i.e., the intermediated user node202 corresponding to User “B”), and thus User “A” may be consideredrelevant to User “C,” but because the user node 202 for User “A” is asecond-degree connection with respect to User “C,” that particularconcept node 204 may be considered less relevant than a user node 202that is connected to the user node for User “C” by a single edge 206,such as, for example, the user node 202 corresponding to User “B.” Asyet another example and not by way of limitation, the concept node for“Online Poker” (which may correspond to an online multiplayer game) isnot connected to the user node for User “C” by any pathway in socialgraph 200, and thus the concept “Online Poker” may not be consideredrelevant to User “C.” In particular embodiments, a second node may onlybe considered relevant to the first user if the second node is within athreshold degree of separation of the first user node 202. As an exampleand not by way of limitation, if the threshold degree of separation isthree, then the user node 202 corresponding to User “D” may beconsidered relevant to the concept node 204 corresponding to the recipe“Chicken Parmesan,” which are within three degrees of each other onsocial graph 200 illustrated in FIG. 2. However, continuing with thisexample, the concept node 204 corresponding to the application “AllAbout Recipes” would not be considered relevant to the user node 202corresponding to User “D” because these nodes are four degrees apart inthe social graph 200. Although this disclosure describes determiningwhether particular social-graph elements (and thus their correspondingquery tokens) are relevant to each other in a particular manner, thisdisclosure contemplates determining whether any suitable social-graphelements are relevant to each other in any suitable manner. Moreover,although this disclosure describes determining whether particular querytokens corresponding to user nodes 202 and concept nodes 204 arerelevant to a querying user, this disclosure contemplates similarlydetermining whether any suitable query token (and thus any suitablenode) is relevant to any other suitable user.

In particular embodiments, the social-networking system 160 maydetermine the score for a selected grammar based social-graphinformation corresponding to the query tokens of the grammar. As anexample and not by way of limitation, when determining a probability, p,that an n-gram corresponds to a particular social-graph element, thecalculation of the probability may also factor in social-graphinformation. Thus, the probability of corresponding to a particularsocial-graph element, k, given a particular search query, X, andsocial-graph information, G, may be calculated as p=(k|X,G). Theindividual probabilities for the identified nodes and edges may then beused to determine the score for a grammar using those social-graphelements as query tokens. In particular embodiments, the score for aselected grammar may be based on the degree of separation between thefirst user node 202 and the particular social-graph element used as aquery token in the grammar. Grammars with query tokens corresponding tosocial-graph elements that are closer in the social graph 200 to thequerying user (i.e., fewer degrees of separation between the element andthe first user node 202) may be scored more highly than grammars usingquery tokens corresponding to social-graph elements that are furtherfrom the user (i.e., more degrees of separation). As an example and notby way of limitation, referencing FIG. 2, if user “B” inputs a textquery of “chicken,” a grammar with a query token corresponding to theconcept node 204 for the recipe “Chicken Parmesan,” which is connectedto user “B” by an edge 206, may have a relatively higher score than agrammar with a query token corresponding to other nodes associated withthe n-gram chicken (e.g., concept nodes 204 corresponding to “chickennuggets,” or “funky chicken dance”) that are not connected to user “B”in the social graph 200. In particular embodiments, the score for aselected grammar may be based on the identified edges 206 correspondingto the query tokens of the grammar. If the social-networking system 160has already identified one or more edges that correspond to n-grams in areceived text query, those identified edges may then be considered whendetermining the score for a particular parsing of the text query by thegrammar. If a particular grammar comprises query tokens that correspondto both identified nodes and identified edges, if the identified nodesare not actually connected to any of the identified edges, thatparticular grammar may be assigned a zero or null score. In particularembodiments, the score for a selected grammar may be based on the numberof edges 206 connected to the nodes corresponding to query tokens of thegrammar. Grammars comprising query tokens that corresponding to nodeswith more connecting edges 206 may be more popular and more likely to bea target of a search query. As an example and not by way of limitation,if the concept node 204 for “Stanford, Calif.” is only connected by fiveedges while the concept node 204 for “Stanford University” is connectedby five-thousand edges, when determining the score for grammarscontaining query tokens corresponding to either of these nodes, thesocial-networking system 160 may determine that the grammar with a querytoken corresponding to the concept node 204 for “Stanford University”has a relatively higher score than a grammar referencing the conceptnode 204 for “Stanford, Calif.” because of the greater number of edgesconnected to the former concept node 204. In particular embodiments, thescore for a selected grammar may be based on the search historyassociate with the first user (i.e., the querying user). Grammars withquery tokens corresponding to nodes that the first user has previouslyaccessed, or are relevant to the nodes the first user has previouslyaccessed, may be more likely to be the target of the first user's searchquery. Thus, these grammars may be given a higher score. As an exampleand not by way of limitation, if first user has previously visited the“Stanford University” profile page but has never visited the “Stanford,Calif.” profile page, when determining the score for grammars with querytokens corresponding to these concepts, the social-networking system 160may determine that the concept node 204 for “Stanford University” has arelatively high score, and thus the grammar using the correspondingquery token, because the querying user has previously accessed theconcept node 204 for the school. As another example and not by way oflimitation, if the first user has previously visited the concept-profilepage for the television show “Friends,” when determining the score forthe grammar with the query token corresponding to that concept, thesocial-networking system 160 may determine that the concept node 204corresponding to the television show “Friends” has a relatively highscore, and thus the grammar using the corresponding query token, becausethe querying user has previously accessed the concept node 204 for thattelevision show. Although this disclosure describes determining scoresfor particular grammars based on particular social-graph information ina particular manner, this disclosure contemplates determining scores forany suitable grammars based on any suitable social-graph information inany suitable manner.

In particular embodiments, social-networking system 160 may select oneor more grammars having a score greater than a grammar-threshold score.Each of the selected grammars may contain query tokens that correspondto each of the identified nodes or identified edges (which correspond ton-grams of the received text query). In particular embodiments, thegrammars may be ranked based on their determined scores, and onlygrammars within a threshold rank may be selected (e.g., top seven).Although this disclosure describes selecting grammars in a particularmanner, this disclosure contemplates selecting grammars in any suitablemanner.

In particular embodiments, social-networking system 160 may generate oneor more structured queries corresponding to the selected grammars (e.g.,those grammars having a score greater than a grammar-threshold score).Each structured query may be based on a string generated by thecorresponding selected grammar. As an example and not by way oflimitation, in response to the text query “friends stanford”, thegrammar [user][user-filter][school] may generate a string “friends whogo to Stanford University”, where the non-terminal tokens [user],[user-filter], [school] of the grammar have been replaced by theterminal tokens [friends], [who go to], and [Stanford University],respectively, to generate the string. In particular embodiments, astring that is generated by grammar using a natural-language syntax maybe rendered as a structured query in natural language. As an example andnot by way of limitation, the structured query from the previous exampleuses the terminal token [who go to], which uses a natural-languagesyntax so that the string rendered by grammar is in natural language.The natural-language string generated by a grammar may then be renderedto form a structured query by modifying the query tokens correspondingto social-graph element to include references to those social-graphelements. As an example and not by way of limitation, the string“friends who go to Stanford University” may be rendered so that thequery token for “Stanford University” appears in the structured query asa reference to the concept node 204 corresponding to the school“Stanford University”, where the reference may be include highlighting,an inline link, a snippet, another suitable reference, or anycombination thereof. Each structured query may comprise query tokenscorresponding to the corresponding selected grammar, where these querytokens correspond to one or more of the identified edges 206 and one ormore of the identified nodes. Generating structured queries is describedmore below.

In particular embodiments, the social-networking system 160 may generateone or more query modifications for a structured query using acontext-free grammar model. Query modifications are discussed morebelow. A query modification may reference one or more additional nodesor one or more additional edges. This type of query modification may beused to refine or narrow the structured query. Alternatively, a querymodification may reference one or more alternate nodes or one or morealternate edges. This type of query modification may be used to pivot orbroaden the structured query. Collectively, these may be referred to asmodifying nodes and modifying edges, where the modification is to eitheradd or replace a particular query token corresponding to a social-graphelement. The references in the query modification to additional oralternate nodes and edges may be used to add or replace query tokens ina structured query, respectively. To identify possible querymodifications for a structured query, the social-networking system 160may identify one or more grammars having query tokens corresponding tothe selected nodes and selected edges from the original structuredquery. In other words, the social-networking system 160 may identify thegrammar actually used to generate that particular structured query,other grammars that could have produced that structured query, andgrammars that could have that structured query as portion of anotherstructured query. The social-networking system 160 may then identifyquery tokens in those grammars that may be added or replaced in thestructured query. These additional or alternate query tokens may then beused to generate suggested query modifications, which may be transmittedto the querying user as part of a search-results page. The querying usermay then select one or more of these query modifications, and inresponse the social-networking system 160 may generate a new structuredquery (and corresponding search results). This new structured query mayinclude the modifying query tokens (i.e., additional or alternate querytokens) as appropriate. Although this disclosure describes generatingquery modifications in a particular manner, this disclosure contemplatesgenerating query modifications in any suitable manner.

FIG. 6 illustrates an example method 600 for using a context-freegrammar model to generate natural-language structured search queries.The method may begin at step 610, where the social-networking system 160may access a social graph 200 comprising a plurality of nodes and aplurality of edges 206 connecting the nodes. The nodes may comprise afirst user node 202 and a plurality of second nodes (one or more usernodes 202, concepts nodes 204, or any combination thereof). At step 620,the social-networking system 160 may receive from the first user anunstructured text query. The text query may comprise one or moren-grams. At step 630, the social-networking system 160 may identifyedges and second nodes corresponding to at least a portion of theunstructured text query. For example, the social-networking system 160may identify edges and node that correspond to particular n-grams fromthe query. At step 640, the social-networking system 160 may access acontext-free grammar model comprising a plurality of grammars. Eachgrammar may comprise one or more non-terminal tokens and one or morequery tokens (i.e., terminal tokens). At step 650, the social-networkingsystem 160 may identify one or more query tokens in the plurality ofgrammars, where each identified query token corresponds to one of theidentified nodes or identified edges. At step 660, the social-networkingsystem 160 may select one or more grammars, where each of the selectedgrammars comprises at least one query token corresponding to each of theidentified edges and identified second nodes. At step 670, thesocial-networking system may generate one or more structured queriesbased on the selected grammars. Each structured query may correspond tostring generated by the selected grammar, which may use anatural-language syntax. Each structured query may included referencesto each of the identified edges and identified second nodes. Particularembodiments may repeat one or more steps of the method of FIG. 6, whereappropriate. Although this disclosure describes and illustratesparticular steps of the method of FIG. 6 as occurring in a particularorder, this disclosure contemplates any suitable steps of the method ofFIG. 6 occurring in any suitable order. Moreover, although thisdisclosure describes and illustrates particular components, devices, orsystems carrying out particular steps of the method of FIG. 6, thisdisclosure contemplates any suitable combination of any suitablecomponents, devices, or systems carrying out any suitable steps of themethod of FIG. 6.

More information on using grammar models with search queries may befound in U.S. patent application Ser. No. 13/674,695, filed 12 Nov.2012, which is incorporated by reference.

Generating Structured Search Queries

In particular embodiments, social-networking system 160 may generate oneor more structured queries that each comprise the query tokens of thecorresponding grammar, where the query tokens may correspond to one ormore of the identified user nodes 202 or one or more of the identifiededges 206. The generated structured queries may be based onnatural-language strings generated by one or more context-free grammars,as described previously. This type of structured search query may allowthe social-networking system 160 to more efficiently search forresources and content related to the online social network (such as, forexample, profile pages) by searching for content connected to orotherwise related to the identified user nodes 202 and the identifiededges 206. As an example and not by way of limitation, in response tothe text query, “show me friends of my girlfriend,” thesocial-networking system 160 may generate a structured query “Friends ofStephanie,” where “Friends” and “Stephanie” in the structured query arereferences corresponding to particular social-graph elements. Thereference to “Stephanie” would correspond to a particular user node 202,while the reference to “friends” would correspond to “friend” edges 206connecting that user node 202 to other user nodes 202 (i.e., edges 206connecting to “Stephanie's” first-degree friends). When executing thisstructured query, the social-networking system 160 may identify one ormore user nodes 202 connected by “friend” edges 206 to the user node 202corresponding to “Stephanie.” In particular embodiments, thesocial-networking system 160 may generate a plurality of structuredqueries, where the structured queries may comprise references todifferent identified user nodes 202 or different identified edges 206.As an example and not by way of limitation, in response to the textquery, “photos of cat,” the social-networking system 160 may generate afirst structured query “Photos of Catey” and a second structured query“Photos of Catherine,” where “Photos” in the structured query is areference corresponding to a particular social-graph element, and where“Catey” and “Catherine” are references to two different user nodes 202.Although this disclosure describes generating particular structuredqueries in a particular manner, this disclosure contemplates generatingany suitable structured queries in any suitable manner.

In particular embodiments, social-networking system 160 may generate oneor more structured queries that each comprise query tokens correspondingto the identified concept nodes 204 and one or more of the identifiededges 206. This type of structured search query may allow thesocial-networking system 160 to more efficiently search for resourcesand content related to the online social network (such as, for example,profile pages) by search for content connected to or otherwise relatedto the identified concept nodes 204 and the identified edges 206. As anexample and not by way of limitation, in response to the text query,“friends like facebook,” the social-networking system 160 may generate astructured query “My friends who like Facebook,” where “friends,”“like,” and “Facebook” in the structured query are query tokenscorresponding to particular social-graph elements as describedpreviously (i.e., a “friend” edge 206, a “like” edge 206, and a“Facebook” concept node 204). In particular embodiments, thesocial-networking system 160 may generate a plurality of structuredqueries, where the structured queries may comprise references todifferent identified concept nodes 204 or different identified edges206. As an example and not by way of limitation, continuing with theprevious example, in addition to the structured query “My friends wholike Facebook,” the social-networking system 160 may also generate astructured query “My friends who like Facebook Culinary Team,” where“Facebook Culinary Team” in the structured query is a query tokencorresponding to yet another social-graph element. In particularembodiments, social-networking system 160 may rank the generatedstructured queries. The structured queries may be ranked based on avariety of factors. In particular embodiments, the social-networkingsystem 160 may ranks structured queries based on advertisingsponsorship. An advertiser (such as, for example, the user oradministrator of a particular profile page corresponding to a particularnode) may sponsor a particular node such that a structured queryreferencing that node may be ranked more highly. Although thisdisclosure describes generating particular structured queries in aparticular manner, this disclosure contemplates generating any suitablestructured queries in any suitable manner.

In particular embodiments, social-networking system 160 may transmit oneor more of the structured queries to the first user (i.e., the queryinguser). As an example and not by way of limitation, after the structuredqueries are generated, the social-networking system 160 may transmit oneor more of the structured queries as a response (which may utilize AJAXor other suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) of the referencedsocial-graph elements, other query limitations (e.g., Boolean operators,etc.), as well as, potentially, other metadata associated with thereferenced social-graph elements. The web browser 132 on the queryinguser's client system 130 may display the transmitted structured queriesin a drop-down menu 300, as illustrated in FIGS. 4A-4B. In particularembodiments, the transmitted queries may be presented to the queryinguser in a ranked order, such as, for example, based on a rank previouslydetermined as described above. Structured queries with better rankingsmay be presented in a more prominent position. Furthermore, inparticular embodiments, only structured queries above a threshold rankmay be transmitted or displayed to the querying user. As an example andnot by way of limitation, as illustrated in FIGS. 4A-4B, the structuredqueries may be presented to the querying user in a drop-down menu 300where higher ranked structured queries may be presented at the top ofthe menu, with lower ranked structured queries presented in descendingorder down the menu. In the examples illustrated in FIGS. 4A-4B, onlythe seven highest ranked queries are transmitted and displayed to theuser. In particular embodiments, one or more references in a structuredquery may be highlighted (e.g., outlined, underlined, circled, bolded,italicized, colored, lighted, offset, in caps) in order to indicate itscorrespondence to a particular social-graph element. As an example andnot by way of limitation, as illustrated in FIGS. 4A-4B, the referencesto “Stanford University” and “Stanford, Calif.” are highlighted(outlined) in the structured queries to indicate that it corresponds toa particular concept node 204. Similarly, the references to “Friends”,“like”, “work at”, and “go to” in the structured queries presented indrop-down menu 300 could also be highlighted to indicate that theycorrespond to particular edges 206. Although this disclosure describestransmitting particular structured queries in a particular manner, thisdisclosure contemplates transmitting any suitable structured queries inany suitable manner.

In particular embodiments, social-networking system 160 may receive fromthe first user (i.e., the querying user) a selection of one of thestructured queries. Alternatively, the social-networking system 160 mayreceive a structured query as a query selected automatically by thesystem (e.g., a default selection) in certain contexts. The nodes andedges referenced in the received structured query may be referred to asthe selected nodes and selected edges, respectively. As an example andnot by way of limitation, the web browser 132 on the querying user'sclient system 130 may display the transmitted structured queries in adrop-down menu 300, as illustrated in FIGS. 4A-4B, which the user maythen click on or otherwise select (e.g., by simply keying “enter” on hiskeyboard) to indicate the particular structured query the user wants thesocial-networking system 160 to execute. Upon selecting the particularstructured query, the user's client system 130 may call or otherwiseinstruct to the social-networking system 160 to execute the selectedstructured query. Although this disclosure describes receivingselections of particular structured queries in a particular manner, thisdisclosure contemplates receiving selections of any suitable structuredqueries in any suitable manner.

More information on structured search queries may be found in U.S.patent application Ser. No. 13/556,072, filed 23 Jul. 2012, which isincorporated by reference.

Generating Search Results and Snippets

FIGS. 7A-7G illustrate example search-results pages. In response to astructured query received from a querying user (also referred to as the“first user”), the social-networking system 160 may generate one or moresearch results, where each search result matches (or substantiallymatches) the terms of the structured query. In particular embodiments,the social-networking system 160 may receive a structured query from aquerying user (also referred to as the “first user”, corresponding to afirst user node 202). In response to the structured query, thesocial-networking system 160 may generate one or more search resultscorresponding to the structured query. Each search result may includelink to a profile page and a description or summary of the profile page(or the node corresponding to that page). The search results may bepresented and transmitted to the querying user as a search-results page.FIGS. 7A-7G illustrate various example search-results pages generated inresponse to various structured queries. The structured query used togenerate a particular search-results page is shown in query field 350,and the various search results generated in response to the structuredquery are illustrated in results field 710. In particular embodiments,the query field 350 may also serve as the title bar for the page. Inother words, the title bar and query field 350 may effectively be aunified field on the search-results page. As an example, FIG. 7Gillustrates a search-results page with the structured query “Photos ofmy friends from Tennessee” in query field 350. This structured queryalso effectively serves as the title for the generated page, where thepage shows a plurality of photos of the querying user's friends who arefrom Tennessee. The search-results page may also include a modificationsfield 720, a suggested-searches field 730, an expanded-searches field740, or a disambiguation field 750. These additional fields arediscussed more below. When generating the search results, thesocial-networking system 160 may generate one or more snippets for eachsearch result, where the snippets are contextual information about thetarget of the search result (i.e., contextual information about thesocial-graph entity, profile page, or other content corresponding to theparticular search result). In particular embodiments, at least onesnippet for each search result will be a lineage snippet, whichdescribes how the search result matches to the selected node andselected edges from the structured query that was used to generate thesearch result. These lineage snippets provide context about how aparticular search result satisfies the terms of the structured querywith respect to social-graph elements. Although this disclosuredescribes and illustrates particular search-results pages, thisdisclosure contemplates any suitable search-results pages. Furthermore,although this disclosure describes and illustrates generating particularsnippets in a particular manner, this disclosure contemplates generatingany suitable snippets in any suitable manner.

In particular embodiments, the social-networking system 160 may generateone or more search results corresponding to a structured query. Thesearch results may identify resources or content (e.g., user-profilepages, content-profile pages, or external resources) that match or arelikely to be related to the search query. In particular embodiments,each search result may correspond to a particular user node 202 orconcept node 204 of the social graph 200. The search result may includea link to the profile page associated with the node, as well ascontextual information about the node (i.e., contextual informationabout the user or concept that corresponds to the node). As an exampleand not by way of limitation, referencing FIG. 7B, the structured query“My friends who work at Facebook” in query field 350 generated thevarious search results illustrated in results field 710. Each searchresult in results field 710 shows a link to a profile page of a user(illustrated as the user's name, which contains an inline link to theprofile page) and contextual information about that user thatcorresponds to a user node 202 of the social graph 200. As anotherexample and not by way of limitation, referencing FIG. 7G, thestructured query “Photos of my friends from Tennessee” in query field350 generated the various search results illustrated in results field710. Each search result illustrated in FIG. 7G shows a thumbnail of aphotograph that corresponds to a concept node 204 of the social graph.In particular embodiments, each search result may correspond to a nodethat is connected to one or more of the selected nodes by one or more ofthe selected edges of the structured query. As an example and not by wayof limitation, referencing FIG. 2, if user “C” submits a structuredquery “Friends who like the Old Pro”, which references the friend-typeedge 206 and the concept node 204 of the location “Old Pro”, thesocial-networking system 160 may return a search result corresponding touser “B” because the user node 202 of user “B” is connected to the usernode 202 of user “C” by a friend-type edge 206 and also connected to theconcept node 204 of the location “Old Pro” by a like-type edge 206. Inparticular embodiments, the social-networking system 160 may alsotransmit advertisements or other sponsored content to the client system130 in response to the structured query. The advertisements may beincluded in as part of the search results, or separately. Theadvertisements may correspond to one or more of the objects referencedin the search results. In particular embodiments, the social-networkingsystem 160 may filter out one or more search results identifyingparticular resources or content based on the privacy settings associatedwith the users associated with those resources or content. Although thisdisclosure describes generating particular search results in aparticular manner, this disclosure contemplates generating any suitablesearch results in any suitable manner.

In particular embodiments, a search result may include one or moresnippets. A snippet is contextual information about the target of thesearch result. In other words, a snippet provides information about thatpage or content corresponding to the search result. As an example andnot by way of limitation, a snippet may be a sample of content from theprofile page (or node) corresponding to the search result. A snippet maybe included along with search results for any suitable type of content.In particular embodiments, the snippets displayed with a search resultmay be based on the type of content corresponding to the search result.As an example and not by way of limitation, if the querying user issearching for users, then the snippets included with the search resultsmay be contextual information about the users displayed in the searchresults, like the user's age, location, education, or employer. Asanother example and not by way of limitation, if the querying user issearching for photos, then the snippets included with the search resultsmay be contextual information about the photos displayed in the searchresults, like the names of people or objects in the photo, the number oflikes/views of the photo, or the location where the photo was taken. Asyet another example and not by way of limitation, if the querying useris search for a location, then the snippets included with the searchresults may be contextual information about the locations displayed inthe search results, like the address of the location, operating hours ofthe location, or the number of likes/check-ins at the location. Theinformation provided in a snippet may be selected by theowner/administrator of the target page, or may be selected automaticallybe the social-networking system 160. Snippets may be used to display keyinformation about a search result, such as image thumbnails, summaries,document types, page views, comments, dates, authorship, ratings,prices, or other relevant information. In particular embodiments, asnippet for a search result corresponding to users/concepts in an onlinesocial network may include contextual information that is provided byusers of the online social network or otherwise available on the onlinesocial network. As an example and not by way of limitation, a snippetmay include one or more of the following types of information: privacysettings of a group; number of members in a group; sponsored messages(e.g., an inline ad unit rendered as a snippet); page categories;physical address; biographical details; interests; relationship status;sexual orientation/preference; sex/gender; age; birthday; current city;education history; political affiliations; religious beliefs; workhistory; applications used; comments; tags; other suitable contextualinformation; or any combination thereof. In particular embodiments, asnippet may include references to nodes or edges from the social graph200. These snippets may be highlighted to indicate the referencecorresponds to a social-graph element. As an example and not by way oflimitation, FIG. 7F illustrates a search result for the user “Sol”,where one of the snippets for that search result is “Likes Reposado, TheSlanted Door, and 12 others.” The terms “Reposado” and “The SlantedDoor” are both highlighted (underlined) in this example to indicate thatthey are references to concept nodes 204 corresponding to the concepts“Reposado” and “The Slanted Door”, which are restaurants liked by theuser “Sol” (i.e., the user node 202 for “Sol” is connected to theconcept nodes 204 for “Reposado” and “The Slanted Door” by a like-typeedge 206). The highlighted references in this example also containinline links to the concept-profile pages corresponding to “Reposado”and “The Slanted Door”. In particular embodiments, the social-networkingsystem 160 may filter out one or more snippets for a search result basedon the privacy settings associated with the user identified by thesearch result. Although this disclosure describes particular types ofsnippets, this disclosure contemplates any suitable types of snippets.

In particular embodiments, a search result may include at least onesnippet comprising one or more references to the selected nodes and theselected edges of a structured search query. In other words, in responseto a structured search query, the social-networking system 160 maygenerate a search result with a snippet providing contextual informationrelated to how the search result matches the search query. These may bereferred to as lineage snippets, since they provide social-graphinformation (node/edge relationship information) contextualizing how theparticular search result is related to the social-graph elements of thestructured query. In other words, a lineage snippet is a way ofproviding proof to the querying user that a particular search resultsatisfies a structured query. As an example and not by way oflimitation, FIG. 7D illustrates a search-results page for the structuredquery “My friends who work at Facebook and work at Acme as softwareengineers.” The social-graph elements referenced in the structured queryinclude “my friends” (i.e., user nodes 202 connected to the queryinguser's node by a friend-type edge 206), “who work at Facebook (i.e.,user nodes 202 connected to the concept node 204 for “Facebook” by awork-at-type edge 206), and “work at Acme” (i.e., user nodes 202connected to the concept node 204 for “Acme” by a work-at-type edge206). The first search result illustrated in FIG. 7D for “Luke” includesa snippet stating “Director of Engineering at Facebook”, whichcorresponds to the “who work at Facebook” token from the structuredquery. Thus, this snippet shows that the search result for “Luke”satisfies the “who work at Facebook” requirement of the structured querybecause “Luke” is “Director of Engineering at Facebook.” Other snippetsin the “Luke” search result provide further context showing how thatsearch result satisfies the other criteria of the structured query. Inother words, the user node 202 for “Luke” is connected to the conceptnode 204 for “Facebook” by a work-at-type edge 206. In particularembodiments, a lineage snippet may include one or more of the followingtypes of social-graph information: school attended; worked in/at; pagesliked; apps used; subscribing to; subscribed by; family relationships;relationship connections (married to; dating; etc.); lives in/near;places checked into; places visited by; number of friends that live at alocation; number of friends that study at a location; friends that aremembers of a group; number of likes; number of people talking about apage; number of subscribers; friends using an application; number ofusers of an application; people tagged in media; people commented on/inmedia; people who created media; other suitable social-graphinformation; or any combination thereof. In particular embodiments, oneor more of the references to the selected nodes or the selected edges inthe lineage snippet may be highlighted to indicate that the referencecorresponds to a selected node or a selected edge. Although thisdisclosure describes particular types of lineage snippets, thisdisclosure contemplates any suitable types of lineage snippets.

In particular embodiments, a search result may include a snippetcomprising a reference to one or more nodes that are connected to theuser node 202 of the querying user by one or more edges 206. In otherwords, the search result may include a snippet with contextualinformation about how the search result is related to the queryinguser's friends or related to concept nodes 204 connected to the user.These may be referred to as social snippets, since they providesocial-graph information (node-edge relationship information)contextualizing how the particular search result is connected to thequerying user and/or the user's friends/interests. As an example and notby way of limitation, FIG. 7D illustrates a search-results page for thestructured query “My friends who work at Facebook and work at Acme assoftware engineers.” The first search result illustrated in FIG. 7D for“Luke” includes a snippet stating “Your friend since April 2009”. Thissnippet provides contextual information about how the “Luke” searchresult is related to the querying user. In other words, the user node202 for “Luke” is connected to the querying user's node by a friend-typeedge 206. The “Luke” search result also includes a snippet stating “197mutual friends included Sol and Steven.” This snippet providescontextual information about how the “Luke” search result is related toother nodes connected to the querying user. In other words, both theuser node 202 of the querying user and the user node 202 for “Luke” areconnected to the same 197 user nodes 202 by friend-type edges 206. Inparticular embodiments, the search result may include multilevel lineagesnippet. A multilevel lineage snippet provides contextual informationabout how users or concepts references in the snippet may be related tothe query tokens from the structured query. This may be used in responseto complex structured queries. As an example and not by way oflimitation, user “A” and user “D” may be connected in the social graph200 by a brother-type edge 206 (indicating that they are brothers). Inresponse to a structured query for “Show people who are brothers of Acmeemployees”, the social-networking system 160 may generate a searchresult for user “A” with a snippet stating, “Brother of User D. User Dis a software engineer at Acme”. This snippet provides contextualinformation about how the user “A” search result is related to user “D”(they are brothers, connected by a brother-type edge 206), and how user“D” is related to “Acme” (user “D” is connected to “Acme” by aworked-at-type edge 206). Although this disclosure describes particulartypes of social snippets, this disclosure contemplates any suitabletypes of social snippets.

In particular embodiments, a search result may include a snippet thatincludes a customized structured query. This may be presented, forexample, as an inline link within the snippet. The querying user maythen be able to click or otherwise select once of a customizedstructured queries to transmit the query to the social-networking system160. In particular embodiments, the customized structured query may becustomized based on the associated search result, such that thecustomized structured query includes a reference to the nodecorresponding to the search result (and possible references to othersocial-graph elements. As an example and not by way of limitation,referencing FIG. 7A, the search result for “Paul” includes a snippetreading “Browse his Photos, Friends, Interests”, where “Photo”,“Friends”, and “Interests” are each customized structured queries tosearch for “Photos of Paul” (i.e., concept nodes 204 of photos that areconnected to the user node 202 of “Paul” by a tagged-in-type edge 206),“Friends of Paul”, and “Interests of Paul” (i.e., concept nodes 204 thatare connected to the user node of “Paul” by an interested-in-type edge206), respectively. In particular embodiments, the customized structuredquery may be customized based on the associated search result and theselected nodes/edges from the original structured query (i.e., thestructured query that was used to produce the search result). Thesecustomized structured queries would then include a reference to the nodecorresponding to the search result and references to the selected nodesand the selected edges from the original structured query. These may bereferred to as lineage-pivot snippets, since they are based on thesocial-graph elements from the original structured query, like a lineagesnippet, as well as the node corresponding to the search result, thuspivoting the query based on the search result. As an example and not byway of limitation, again referencing FIG. 7A, the structured query“People who currently work for Facebook and like Unicycling” generatedthe search results illustrated in results field 710. The search resultfor “Tom” could include a snippet with a structured query “Friends ofTom who like Unicycling”, thus referencing both the user node 202 of thesearch result (i.e., the user node 202 of “Tom”) and a selected node andselected edge from the original structured query (i.e., the concept node204 for “Unicycling” connected by a like-type edge 206). As anotherexample and not by way of limitation, referencing FIG. 7F, thestructured query “People who like mexican restaurants in Palo Alto,Calif.” generated the search results illustrated in results field 710.The search result for “Sol” includes a snippet “Like Reposado, TheSlanted Door and 12 others”, where “Reposado” and “The Slanted Door” areboth reference to concept nodes 204 for particular Mexican restaurantsin Palo Alto. Similarly, the reference to “12 others” could be an inlinelink for a structured query “Mexican restaurants liked by Sol in PaloAlto, Calif.”, thus referencing both the user node 202 of the searchresult (i.e., the user node 202 of “Sol”) and a selected node andselected edge from the original structured query (i.e., the concept node204 for “Palo Alto, Calif.” and the like-type edge 206). Although thisdisclosure describes generating particular snippets with customizedstructured queries, this disclosure contemplates generating any suitablesnippets with customized structured queries.

In particular embodiments, the social-networking system 160 may scoreone or more snippets corresponding to a search result (or snippetscorresponding to a node or profile page that is the target of the searchresult). In response to a structured query, the social-networking system160 may identify nodes corresponding to the query and then access one ormore snippets corresponding to each of these identified nodes. Thesocial-networking system 160 may then determine, for each search result,a score for each of the snippets corresponding to the search result.When generating a search result, only those snippets having a scoregreater than a snippet-threshold score may be included in the searchresult. The score may be, for example, a confidence score, aprobability, a quality, a ranking, another suitable type of score, orany combination thereof. As an example and not by way of limitation, thesocial-networking system 160 may determine a ranking for each snippet,where only the top five ranked snippets are included in a particularsearch result. Alternatively, the social-networking system 160 may scoreeach snippet and include all available snippets with the search result,presented in ranked order by score (possibly bypassing a rankingthreshold to display a greater number of snippets with a search result).Furthermore, different search results may include different numbers ofsnippets. For example, a first search result may only have two snippetsassociated with it and both snippets might be displayed in ranked orderby score, while a second search result may have nine snippets associatedwith it and all nine snipped may be displayed in ranked order by score.In particular embodiments, the social-networking system 160 maydetermine a score for a snippet based on the social relevance of thesnippet to the structured query. Snippets that reference social-graphelements that are more closely connected or otherwise relevant to thequerying user may be scored more highly than snippets that referencesocial-graph elements that are not as closely connected or are otherwiseless relevant to the querying user. In particular embodiments, thesocial-networking system 160 may determine a score for a snippet basedon the textual relevance of the snippet to the structured query. Thetextual relevance of a particular snippet may be based on how the termsand number of terms in the particular snippet match to the text queryreceived from the querying user. In particular embodiments, thesocial-networking system 160 may determine a score for a snippet basedon a search history associated with the querying user. Snippetsreferencing social-graph elements that the querying user has previouslyaccessed, or are relevant to nodes/profile pages the querying user haspreviously accessed, may be more likely to be relevant to the user'sstructured query. Thus, these snippets may be given a higher relativescore. As an example and not by way of limitation, if the querying userhas previously search for “My female friends who are single”, then thesocial-networking system 160 may determine that the querying user isinterested in the relationship status of people he is searching forbecause of the query modifier “who are single” in the query, which willsearch for users having a relationship status of “single”. Thus, inresponse to subsequent queries (e.g., “Facebook engineers who went toStanford University”, as illustrated in FIG. 7E), the social-networkingsystem 160 may score snippets showing the relationship status of thesearch result more highly than other snippets because of the queryinguser's history of interest in that type of contextual information (thus,the search results illustrated in FIG. 7E may have scored the snippetsshowing the relationship statues for each search result more highly,such as, for example “in a relationship” or “married”). In particularembodiments, the social-networking system 160 may determine a score fora snippet based on a category of the search. Searches may be categorizedbased on the type of content that is the subject of the search. Snippetsthat are more relevant to the type of content being searched for may bescored more highly than less relevant snippets. As an example and not byway of limitation, when searching for user, snippets that includepersonal information about the user (e.g., location, relationshipstatus, etc.) may be scored more highly than other types of snippets,since personal information may be considered more relevant to a queryinguser searching for other users. As another example and not by way oflimitation, when searching for concepts, snippets that includesocial-graph information about the concept (e.g., number ofsubscribers/fan, number of likes, number of check-ins/reviews, etc.) maybe scored more highly than other types of snippets, since social-graphinformation may be more relevant to a querying user searching forconcepts. In particular embodiments, the social-networking system 160may determine a score for a snippet based on advertising sponsorship. Anadvertiser (such as, for example, the user or administrator of aparticular profile page corresponding to a particular node) may sponsora particular node such that a snippet referencing that node may bescored more highly. Although this disclosure describes scoring snippetsin a particular manner, this disclosure contemplates scoring snippets inany suitable manner.

FIG. 8 illustrates an example method 800 for generating search resultsand snippets. The method may begin at step 810, where thesocial-networking system 160 may access a social graph 200 comprising aplurality of nodes and a plurality of edges 206 connecting the nodes.The nodes may comprise a first user node 202 and a plurality of secondnodes (one or more user nodes 202, concepts nodes 204, or anycombination thereof). At step 820, the social-networking system 160 mayreceiving from the first user a structured query comprising referencesto one or more selected node from the plurality of second nodes and oneor more selected edges from the plurality of edges. At step 830, thesocial-networking system 160 may generate search results correspondingto the structured query. Each search result may correspond to a secondnode of the plurality of second nodes. Furthermore, each search resultmay comprise one or more snippets of contextual information about thesecond node corresponding to the search result. At least one snippet ofeach search result comprises one or more references to the selectednodes and the selected edges of the structured query. Particularembodiments may repeat one or more steps of the method of FIG. 8, whereappropriate. Although this disclosure describes and illustratesparticular steps of the method of FIG. 8 as occurring in a particularorder, this disclosure contemplates any suitable steps of the method ofFIG. 8 occurring in any suitable order. Moreover, although thisdisclosure describes and illustrates particular components, devices, orsystems carrying out particular steps of the method of FIG. 8, thisdisclosure contemplates any suitable combination of any suitablecomponents, devices, or systems carrying out any suitable steps of themethod of FIG. 8.

Modifying Structured Search Queries

As discussed previously, FIGS. 7A-7G illustrate example search-resultspages. The structured query used to generate a particular search-resultspage is shown in query field 350, and the various search resultsgenerated in response to the structured query are illustrated in resultsfield 710. In response to a structured query received from a queryinguser, the social-networking system 160 may generate one or more querymodifications that may be used to refine or pivot the query. The querymodifications may reference particular social-graph elements, allowingthe querying user to add or replace the social-graph elements referencedin a structured query. In particular embodiments, one or more querymodifications may be presented on a search-results page in amodifications field 720, a suggested-searches field 730, anexpanded-searches field 740, or a disambiguation field 750. Querymodifications may be used to refine or narrow a structured query byadding additional terms to the query. In general, adding additionalterms to a structured query will reduce the number of search resultsgenerated by the query. As an example and not by way of limitation, inresponse to the structured query “My friends who go to StanfordUniversity,” the social-networking system 160 may generate querymodifications to the “My friends” term such as, for example, “My[male/female] friends” to filter the search results by sex, or “My[single/married] friends” to filter the search results by relationshipstatus. Query modifications may also be used to pivot or broaden astructured query by changing one or more terms of the query. As anexample and not by way of limitation, in response to the structuredquery “My friends who work at Facebook”, the social-networking system160 may generate the query modification “work at Acme”, which canreplace the “work at Facebook” term, thereby pivoting the query fromsearching one set of users to searching another set. By providing thesesuggested query modifications to the querying user, thesocial-networking system 160 may provide a powerful way for users tosearch for exactly what they are looking for. Once a query modificationis selected by the querying user, a new structured query may begenerated using an appropriate grammar, such that the new structuredquery is also rendered using a natural-language syntax. Thesocial-networking system 160 may also generate alternative structuredqueries that may be displayed on the search-results page. Thesealternative structured queries include suggested queries, broadeningqueries, and disambiguation queries, which are described more below.Although this disclosure describes generating querying modifications ina particular manner, this disclosure contemplates query modifications inany suitable manner. Moreover, although this disclosure describespresenting query modifications to users in a particular manner, thisdisclosure contemplates presenting query modifications to users in anysuitable manner.

In particular embodiments, the social-networking system 160 may generateone or more query modifications. The query modifications may begenerated in response to receiving a first structured query, such thatthe query modification may be used to modify the first structured query.A query modification may be any type of term that can be used to modifya search query. For example, a query modification may be a text string,an n-gram, a terminal/query token, a value, a property, a queryoperator, another suitable type of term, or any combination thereof. Inparticular embodiments, the query modifications may be organized bycategory. As an example and not by way of limitation, the modificationsfield 720 illustrated in FIG. 7A shows query modifications for“Employer”, “School”, “Current City”, “Hometown”, “Relationship Status”,“Interested in”, “Friendship”, “Gender”, “Name”, and “Likes”. Inparticular embodiments, the query modifications may be transmitted tothe querying user as part of the search-results page. As an example andnot by way of limitation, the search-results pages illustrated in FIGS.7D, 7E, and 7F all illustrate lists of query modifications displayed indrop-down menus in the modifications field 720. The query modificationslisted in these drop-down menus may be used to add or replace terms inthe structured query displayed in search field 350. In particularembodiments, a customized query modification may be generated inconjunction with a typeahead process. Rather than selecting from a listof pre-generated query modifications, a user may input a text string,and the typeahead process may identify social-graph elements thatcorrespond to one or more of the n-grams from the inputted text string.The social-networking system 160 may then present one or more possiblematches. As an example and not by way of limitation, FIG. 7E illustratesthe querying user inputting the string “Harvard” into an input field forthe “School” category in the modifications field 720. In response, thetypeahead process has generated several possible matching querymodifications, including “Harvard”, “Harvard Law School”, and“Harvard-Westlake”, among others. These listed schools displayed in thedrop-down menu are references to concept nodes 204 in the social graph200 that correspond to these schools. Although this disclosure describesand illustrates particular categories of query modifications, thisdisclosure contemplates any suitable categories of query modifications.

In particular embodiments, a query modification may include referencesto one or more modifying nodes or one or more modifying edges from thesocial graph 200. A modifying node or a modifying edge may be used toadd or replace a reference to a node or edge in the first structuredquery. The querying user may then selected one or more of these querymodifications to add the modifying nodes/edges to the first structuredquery, or by replacing nodes/edges in the structured query with one ormore of the modifying nodes/edges. As an example and not by way oflimitation, FIG. 7D illustrates an example search-results page generatedby the structured query “My friends who work at Facebook and work atAcme as software engineers”. The querying user may want to refine thesearch by also specifying a school attended by the users identified bythe search query. To specify a school, the querying user may click onthe “School” drop-down menu, as illustrated in FIG. 7D, which maydisplay a list of query modifications generated by the social-networkingsystem 160. In this case, the drop-down menu in FIG. 7D lists theschools “Stanford University”, “Menlo-Atherton High”, and “UC Berkeley”,among others. These listed schools displayed in the drop-down menu arereferences to concept nodes 204 in the social graph 200 that correspondto these schools. The querying user may then select one or more of thesequery modifications to add the referenced school to the structuredquery, thereby filtering the search results by school. In response tothe selection from the querying user, the social-networking system 160may modify the structured query to include a reference to the selectedschool. As another example and not by way of limitation, FIG. 7Billustrates an example search-results page generated by the structuredquery “My friends who work at Facebook”. The reference to “my friends”corresponds to user nodes 202 connected to the querying user by afriend-type edge 206, while the reference to “Facebook” corresponds tothe concept node 204 for the company “Facebook.” These references toparticular nodes and edges in the structured query are shown in themodifications field 720 illustrated in FIG. 7B, where the category for“Employer” already has the term “Facebook” selected, while the categoryfor “Friendship” already has the term “My friends” selected. However,the querying user may want to pivot the search to instead search forfriends at another company. To modify the query, the querying user mayselect the “Employer” category to change the reference from “Facebook”to another company, such as, for example, “Acme.” When the querying userselects the “Employer” category, the social-networking system 160 maydisplay a list of query modifications that have been generated for thatcategory. In response to a selection from the querying user, thesocial-networking system 160 may then modify the structured query andreplace the reference to “Facebook” with a reference to “Acme” (suchthat the new structured query would be “My friends who work at Acme”),thereby pivoting the search from one set of friends to another. Althoughthis disclosure describes using particular query modifications in aparticular manner, this disclosure contemplates using any suitable querymodifications in any suitable manner.

In particular embodiments, the social-networking system 160 may generatea second structured query in response to a selection of one or more ofthe query modifications. The querying user may select one or more of thequery modifications from the menus illustrated in modifications field720, for example, by clicking or otherwise selecting a particular querymodification. In particular embodiments, the query modification mayreference additional nodes or additional edges for the first structuredquery. In this case, the social-networking system 160 may generate asecond structured query comprising references to the selected nodes andthe selected edges from the first structured query, and each modifyingnode or modifying edge referenced in the selected query modification. Asan example and not by way of limitation, for the first structured query“My friends in San Jose”, the social-networking system 160 may receivethe query modification “work at Acme” (which references connections tothe concept node 204 for “Acme” by a worked-at-type edge 206). Thesocial-networking system 160 may then generate a second structured query“My friends in San Jose who work at Acme”, which incorporates theaddition node and additional edge referenced in the query modification.In particular embodiments, the query modification may referencealternative nodes or alternative edges for the first structured query.In this case, the social-networking system 160 may generate a secondstructured query comprising references to the selected nodes and theselected edges from the first structured query, except each reference toan alternative node replaces a reference to a selected node of the firststructured query. Similarly, each reference to an alternative edgereplaces a reference to a selected edge of the first structured query.As an example and not by way of limitation, for the first structuredquery “My friends in San Jose”, the social-networking system 160 mayreceive the query modification “in San Francisco” (which referencesconnections to the concept node 204 for the city “San Francisco” bylive-in-type edges 206). The social-networking system 160 may thengenerate a second structured query “My friends in San Francisco”, whichreplaces the reference to the selected node/edge “in San Jose” from thefirst structured query with the alternative node/edge “in SanFrancisco”. Although this disclosure describes generating particularmodified structured queries in a particular manner, this disclosurecontemplates generating any suitable modified structured queries in anysuitable manner.

In particular embodiments, the social-networking system 160 may scoreone or more query modifications for a first structured query. Inresponse to a structured query, the social-networking system 160 mayidentify one or more query modifications that may be used to modifystructured query. The social-networking system 160 may then determine ascore for each of the identified query modifications. When generating aset of query modifications to transmit to a querying user, only thosequery modifications having a score greater than aquery-modification-threshold score may be included in the set of querymodifications that are actually transmitted. The score may be, forexample, a confidence score, a probability, a quality, a ranking,another suitable type of score, or any combination thereof. As anexample and not by way of limitation, the social-networking system 160may determine a ranking for each query modification, where only the topsix ranked query modifications are included in a particular searchresult. In particular embodiments, the social-networking system 160 maydetermine a score for a query modification based on the social relevanceof the query modification to the structured query. Query modificationsthat reference social-graph elements that are more closely connected orotherwise relevant to the querying user may be scored more highly thanquery modifications that reference social-graph elements that are not asclosely connected or are otherwise less relevant to the querying user.In particular embodiments, the social-networking system 160 maydetermine a score for a query modification based on the number ofpossible search results corresponding to the query modification. Querymodifications that would generate more results (i.e., filter out fewerresults) may be scored more highly than query modifications thatgenerate fewer results. In other words, a query modification that, whenused to modify to the first structured query, will match more results(or more of the current results) may be scored more highly than a querymodification that will match fewer results. As an example and not by wayof limitation, FIG. 7D illustrates possible query modifications for the“School” category in modification field 720. The query modificationreferencing “Stanford University” may be ranked highly in this list ofsuggested query modifications because many search results match thislimitation. In other words, of the user nodes 202 corresponding to thesearch results in results field 710, many of those user nodes 202 may beconnected to the concept node 204 for “Stanford University” by an edge206. Thus, if a reference to the concept node 204 for “StanfordUniversity” was added to the structured query illustrated in query field350, many of the current search results would still match the structuredquery (i.e., few would be filtered out). Similarly, lower ranked schoolsin the drop-down menu, such as “Carnegie Mellon University” and “SantaClara University” may match fewer of the current results (i.e., wouldfilter out more results), and as such are ranked lower. Pivoting querymodifications may be scored similarly. In particular embodiments, thesocial-networking system 160 may determine a score for a querymodification based on a search history associated with the queryinguser. Query modifications referencing social-graph elements that thequerying user has previously accessed, or are relevant to nodes/profilepages the querying user has previously accessed, may be more likely tobe relevant to the user's structured query. Thus, these querymodifications may be given a higher relative score. As an example andnot by way of limitation, if the querying user has previously search for“My friends at Stanford University”, then the social-networking system160 may determine that the querying user is interested in user nodes 202connected to the concept node 204 for “Stanford University.” Thus, inresponse to subsequent queries, the social-networking system 160 mayrank query modifications referencing “Stanford University” more highlythan other query modifications because of the querying user's history ofinterest in that type of contextual information (thus, the searchresults illustrated in FIG. 7D may have ranked the query modificationsfor “Stanford University more highly). In particular embodiments, thesocial-networking system 160 may determine a score for a querymodification based on advertising sponsorship. An advertiser (such as,for example, the user or administrator of a particular profile pagecorresponding to a particular node) may sponsor a particular node suchthat a query modification referencing that node may be scored morehighly. Although this disclosure describes scoring query modificationsin a particular manner, this disclosure contemplates scoring querymodifications in any suitable manner.

In particular embodiments, in response to a first structured query, thesocial-networking system 160 may generate one or more second structuredqueries to pivot the structured query. Each of these second structuredqueries may be based on the first structured query. These may bereferred to as suggested queries. These suggested queries may bevariations of the first structured query, where the suggested query usesat least some of the same query tokens as the first structured query.However, in order to pivot the query, one or more of the query tokensfrom the first structured query may be replaced with alternative querytokens. In other words, the social-networking system 160 may replace oneor more references to selected nodes/edges from the first structuredquery with one or more references to alternative nodes/edges in order togenerate one or more second structured queries. The alternative querytokens may be determined by identifying query tokens that, ifsubstituted into the first structured query, would produce similarsearch results. As an example and not by way of limitation, for thefirst structured query “My friends who go to Stanford University”, thesocial-networking system 160 may identify one or more query tokens thatmay be substituted into the first structured query. For example, thequery token for “Stanford University” may be replaced by other schools.As another example, the query tokens for “who go to” and “StanfordUniversity” may both be replaced by query tokens for “who live in” and“Palo Alto”. This latter example may produce many of the same searchresults as the first structured query because of the high overlapbetween users who live in the city Palo Alto and users who attend theschool Stanford University since the school is geographical proximate tothe city (i.e., in the social graph 200, there may be a large overlapbetween user nodes 202 that are connected to the concept node 204 for“Stanford” and the concept node 204 for “Palo Alto”). The alternativequery tokens may also be determined by using templates based on theoriginal query. As an example and not by way of limitation, if the firststructured query is search for users, the suggested queries may also besearches for user. Similarly, if the first structured query is a searchfor photos, the suggested queries may also be searches for photos. Inparticular embodiments, the suggested queries may be transmitted to thequerying user as part of the search-results page. As an example and notby way of limitation, the search-results page illustrated in FIG. 7Bshows some example suggested queries in the suggested-searches field730. In response to the first structured query “My friends who work atFacebook”, the social-networking system 160 generated the suggestedstructured queries “My friends of friends who like Facebook” and “Myfriends who live in Palo Alto, Calif.”, among others, which are shown insuggested-searches field 730. These suggested queries may have beengenerated based on the first structured query, where one or more of thequery tokens from the first structured query have been replaced.Although this disclosure describes generating structured queries in aparticular manner, this disclosure contemplates generating structuredqueries in any suitable manner.

In particular embodiments, in response to a first structured query, thesocial-networking system 160 may generate one or more second structuredqueries to broaden the structured query. These may be referred to asbroadening queries. These broadening queries may be variations of thefirst structured query, where the broadening query uses less querytokens than the first structured query, or replaces particular querytokens in order to generate more search results. In other words, thesocial-networking system 160 may delete one or more references toselected nodes/edges from the first structured query in order togenerate one or more second structured queries. Similarly, thesocial-networking system 160 may replace one or more references toselected nodes/edges from the first structured query with one or morereferences to alternative nodes/edges in order to generate one or moresecond structured queries. In this case, the alternative query tokensmay be determined by identifying query tokens that, if substituted intothe first structured query, would produce more search results than theoriginal query token. In particular embodiments, broadening structuredqueries may be generated when the search results corresponding to thefirst structured query are below a threshold number of search results.Structured queries with too many limitations, or that use query tokensthat do not match many social-graph entities, may produce few or noresults. When a structured query produces too few results, it may beuseful to provide suggests for how to modify that query to generateadditional result. The social-networking system 160 may analyze thefirst structured query and provide suggestion for how to modify thequery so that it produces more results. The threshold number of searchresults may be any suitable number of results, and may be determined bythe social-networking system 160 or be user-defined. In particularembodiments, the social-networking system 160 may generate one or moresecond structured queries comprising references to zero or more selectednodes and zero or more selected edges from the first structured query,where each second structured query comprises at least one fewerreference to the selected nodes or the selected edges than the firststructured query. As an example and not by way of limitation,referencing FIG. 7A, in response to the first structured query “Peoplewho currently work for Facebook and like Unicycling”, thesocial-networking system 160 generated the broadening queries “Peoplewho like Unicycling” and “Current Facebook employees” inexpanded-searched field 740. These broadening queries may have beengenerated based on the first structured query, where one more or of thequery tokens from the first structured query have been removed (i.e.,the references to “Facebook” and “Unicycling” have been removed,respectively). By removing limitations from the first structured query,more users should satisfy the query and thus these queries shouldgenerate more search results. In particular embodiments, thesocial-networking system 160 may generate one or more second structuredqueries comprising references to zero or more selected nodes and zero ormore selected edges from the first structured query, where each secondstructured query comprises replaces at least one reference to a selectednode or a selected edge of the first structured query with analternative node or an alternative edge, respectively. As an example andnot by way of limitation, referencing FIG. 7A again, thesocial-networking system 160 generated the broadening queries “Peopleinterested in Unicycling Facebook used to employ” and “People interestedin Unicycling Facebook ever employed”. These broadening query may havebeen generated based on the first structured query, where the “currentlywork for” query token has been replaced by “used to employ” and “everemployed” query tokens, respectively, thereby filtering search resultsusing a different timeframe (which may expand the types of connectingedges that may satisfy this query from work-at-type edges 206 to alsoinclude worked-at-type edges 206). In particular embodiments, thebroadening queries may be transmitted to the querying user as part ofthe search-results page. As an example and not by way of limitation, thesearch-results page illustrated in FIG. 7A shows some example broadeningqueries in the expanded-searches field 740, which have been discussedabove. Although this disclosure describes generating particularbroadening queries in a particular manner, this disclosure contemplatesgenerating any suitable broadening queries in any suitable manner.

In particular embodiments, in response to a first structured query, thesocial-networking system 160 may generate one or more second structuredqueries to disambiguate the structured query. These may be referred toas disambiguation queries. These disambiguation queries may bevariations of the first structured query, where the disambiguation queryuses some of the query tokens from the first structured query, but mayalso replace some of the query tokens with alternative query tokens.This may happen where certain nodes may correspond to the same n-gramfrom an unstructured text query from the querying user (e.g., the n-gramfor “stanford” could correspond to the concept node 204 for either theschool “Stanford University” or the city “Stanford, Calif.”).Disambiguation may also be helpful when the referenced edge-types or therelationships between referenced nodes are unclear in the structuredquery. The social-networking system 160 may determine that particularstructured queries are ambiguous, in that the natural-language syntax ofthe structured query may be interpreted in different ways by thequerying user. Consequently, when selecting a particular structuredquery, the social-networking system 160 may generate search results thatare unexpected or not what the querying user was looking for. In thesecases, the social-networking system 160 may provide an explanation ofhow the structured query was parsed and how it identified the displayedsearch results. Additionally, the social-networking system 160 mayprovide variations of the original query to help the querying user findwhat he or she is looking for. In particular embodiments, thedisambiguation queries may be transmitted to the querying user as partof the search-results page. As an example and not by way of limitation,the search-results page illustrated in FIG. 7G illustrates an exampledisambiguation query displayed in disambiguation field 750. In responseto the first structured query “Photos of my friends from Tennessee”, thesocial-networking system 160 generated the disambiguation query “Photosin Tennessee by my friends”. The social-networking system 160 alsoprovided an explanation of how it parsed the first structured query,stating that “These results show photos that belong to friends of yoursfrom Tennessee”. In other words, the social-networking system 160 parsedthe first structured query to identify concept nodes 204 correspondingto photos that were connected to user nodes 202 by a tagged-in-type edge206, and where these user nodes 202 were connected to a concept node 204for “Tennessee” by a lived-in- or from-type edge 206. In contrast, thesuggested disambiguation query would identify concept nodes 204corresponding to photos that were connected to the concept node 204 for“Tennessee” by a taken-in-type edge 206, where the concept nodes 204 forthe photos were also connected to user nodes 202 of the querying user'sfriends. Although this disclosure describes generating particulardisambiguation queries in a particular manner, this disclosurecontemplates generating any suitable disambiguation queries in anysuitable manner.

FIG. 9 illustrates an example method 900 for modifying structured searchqueries. The method may begin at step 910, where the social-networkingsystem 160 may access a social graph 200 comprising a plurality of nodesand a plurality of edges 206 connecting the nodes. The nodes maycomprise a first user node 202 and a plurality of second nodes (one ormore user nodes 202, concepts nodes 204, or any combination thereof). Atstep 920, the social-networking system 160 may receiving from the firstuser a structured query comprising references to one or more selectednode from the plurality of second nodes and one or more selected edgesfrom the plurality of edges. At step 930, the social-networking system160 may generate one or more query modifications for the firststructured query. Each query modification may comprises reference to oneor more modifying nodes form the plurality of second nodes or one ormore modifying edges from the plurality of edges. Particular embodimentsmay repeat one or more steps of the method of FIG. 9, where appropriate.Although this disclosure describes and illustrates particular steps ofthe method of FIG. 9 as occurring in a particular order, this disclosurecontemplates any suitable steps of the method of FIG. 9 occurring in anysuitable order. Moreover, although this disclosure describes andillustrates particular components, devices, or systems carrying outparticular steps of the method of FIG. 9, this disclosure contemplatesany suitable combination of any suitable components, devices, or systemscarrying out any suitable steps of the method of FIG. 9.

Systems and Methods

FIG. 10 illustrates an example computer system 1000. In particularembodiments, one or more computer systems 1000 perform one or more stepsof one or more methods described or illustrated herein. In particularembodiments, one or more computer systems 1000 provide functionalitydescribed or illustrated herein. In particular embodiments, softwarerunning on one or more computer systems 1000 performs one or more stepsof one or more methods described or illustrated herein or providesfunctionality described or illustrated herein. Particular embodimentsinclude one or more portions of one or more computer systems 1000.Herein, reference to a computer system may encompass a computing device,and vice versa, where appropriate. Moreover, reference to a computersystem may encompass one or more computer systems, where appropriate.

This disclosure contemplates any suitable number of computer systems1000. This disclosure contemplates computer system 1000 taking anysuitable physical form. As example and not by way of limitation,computer system 1000 may be an embedded computer system, asystem-on-chip (SOC), a single-board computer system (SBC) (such as, forexample, a computer-on-module (COM) or system-on-module (SOM)), adesktop computer system, a laptop or notebook computer system, aninteractive kiosk, a mainframe, a mesh of computer systems, a mobiletelephone, a personal digital assistant (PDA), a server, a tabletcomputer system, or a combination of two or more of these. Whereappropriate, computer system 1000 may include one or more computersystems 1000; be unitary or distributed; span multiple locations; spanmultiple machines; span multiple data centers; or reside in a cloud,which may include one or more cloud components in one or more networks.Where appropriate, one or more computer systems 1000 may perform withoutsubstantial spatial or temporal limitation one or more steps of one ormore methods described or illustrated herein. As an example and not byway of limitation, one or more computer systems 1000 may perform in realtime or in batch mode one or more steps of one or more methods describedor illustrated herein. One or more computer systems 1000 may perform atdifferent times or at different locations one or more steps of one ormore methods described or illustrated herein, where appropriate.

In particular embodiments, computer system 1000 includes a processor1002, memory 1004, storage 1006, an input/output (I/O) interface 1008, acommunication interface 1010, and a bus 1012. Although this disclosuredescribes and illustrates a particular computer system having aparticular number of particular components in a particular arrangement,this disclosure contemplates any suitable computer system having anysuitable number of any suitable components in any suitable arrangement.

In particular embodiments, processor 1002 includes hardware forexecuting instructions, such as those making up a computer program. Asan example and not by way of limitation, to execute instructions,processor 1002 may retrieve (or fetch) the instructions from an internalregister, an internal cache, memory 1004, or storage 1006; decode andexecute them; and then write one or more results to an internalregister, an internal cache, memory 1004, or storage 1006. In particularembodiments, processor 1002 may include one or more internal caches fordata, instructions, or addresses. This disclosure contemplates processor1002 including any suitable number of any suitable internal caches,where appropriate. As an example and not by way of limitation, processor1002 may include one or more instruction caches, one or more datacaches, and one or more translation lookaside buffers (TLBs).Instructions in the instruction caches may be copies of instructions inmemory 1004 or storage 1006, and the instruction caches may speed upretrieval of those instructions by processor 1002. Data in the datacaches may be copies of data in memory 1004 or storage 1006 forinstructions executing at processor 1002 to operate on; the results ofprevious instructions executed at processor 1002 for access bysubsequent instructions executing at processor 1002 or for writing tomemory 1004 or storage 1006; or other suitable data. The data caches mayspeed up read or write operations by processor 1002. The TLBs may speedup virtual-address translation for processor 1002. In particularembodiments, processor 1002 may include one or more internal registersfor data, instructions, or addresses. This disclosure contemplatesprocessor 1002 including any suitable number of any suitable internalregisters, where appropriate. Where appropriate, processor 1002 mayinclude one or more arithmetic logic units (ALUs); be a multi-coreprocessor; or include one or more processors 1002. Although thisdisclosure describes and illustrates a particular processor, thisdisclosure contemplates any suitable processor.

In particular embodiments, memory 1004 includes main memory for storinginstructions for processor 1002 to execute or data for processor 1002 tooperate on. As an example and not by way of limitation, computer system1000 may load instructions from storage 1006 or another source (such as,for example, another computer system 1000) to memory 1004. Processor1002 may then load the instructions from memory 1004 to an internalregister or internal cache. To execute the instructions, processor 1002may retrieve the instructions from the internal register or internalcache and decode them. During or after execution of the instructions,processor 1002 may write one or more results (which may be intermediateor final results) to the internal register or internal cache. Processor1002 may then write one or more of those results to memory 1004. Inparticular embodiments, processor 1002 executes only instructions in oneor more internal registers or internal caches or in memory 1004 (asopposed to storage 1006 or elsewhere) and operates only on data in oneor more internal registers or internal caches or in memory 1004 (asopposed to storage 1006 or elsewhere). One or more memory buses (whichmay each include an address bus and a data bus) may couple processor1002 to memory 1004. Bus 1012 may include one or more memory buses, asdescribed below. In particular embodiments, one or more memorymanagement units (MMUs) reside between processor 1002 and memory 1004and facilitate accesses to memory 1004 requested by processor 1002. Inparticular embodiments, memory 1004 includes random access memory (RAM).This RAM may be volatile memory, where appropriate Where appropriate,this RAM may be dynamic RAM (DRAM) or static RAM (SRAM). Moreover, whereappropriate, this RAM may be single-ported or multi-ported RAM. Thisdisclosure contemplates any suitable RAM. Memory 1004 may include one ormore memories 1004, where appropriate. Although this disclosuredescribes and illustrates particular memory, this disclosurecontemplates any suitable memory.

In particular embodiments, storage 1006 includes mass storage for dataor instructions. As an example and not by way of limitation, storage1006 may include a hard disk drive (HDD), a floppy disk drive, flashmemory, an optical disc, a magneto-optical disc, magnetic tape, or aUniversal Serial Bus (USB) drive or a combination of two or more ofthese. Storage 1006 may include removable or non-removable (or fixed)media, where appropriate. Storage 1006 may be internal or external tocomputer system 1000, where appropriate. In particular embodiments,storage 1006 is non-volatile, solid-state memory. In particularembodiments, storage 1006 includes read-only memory (ROM). Whereappropriate, this ROM may be mask-programmed ROM, programmable ROM(PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM),electrically alterable ROM (EAROM), or flash memory or a combination oftwo or more of these. This disclosure contemplates mass storage 1006taking any suitable physical form. Storage 1006 may include one or morestorage control units facilitating communication between processor 1002and storage 1006, where appropriate. Where appropriate, storage 1006 mayinclude one or more storages 1006. Although this disclosure describesand illustrates particular storage, this disclosure contemplates anysuitable storage.

In particular embodiments, I/O interface 1008 includes hardware,software, or both, providing one or more interfaces for communicationbetween computer system 1000 and one or more I/O devices. Computersystem 1000 may include one or more of these I/O devices, whereappropriate. One or more of these I/O devices may enable communicationbetween a person and computer system 1000. As an example and not by wayof limitation, an I/O device may include a keyboard, keypad, microphone,monitor, mouse, printer, scanner, speaker, still camera, stylus, tablet,touch screen, trackball, video camera, another suitable I/O device or acombination of two or more of these. An I/O device may include one ormore sensors. This disclosure contemplates any suitable I/O devices andany suitable I/O interfaces 1008 for them. Where appropriate, I/Ointerface 1008 may include one or more device or software driversenabling processor 1002 to drive one or more of these I/O devices. I/Ointerface 1008 may include one or more I/O interfaces 1008, whereappropriate. Although this disclosure describes and illustrates aparticular I/O interface, this disclosure contemplates any suitable I/Ointerface.

In particular embodiments, communication interface 1010 includeshardware, software, or both providing one or more interfaces forcommunication (such as, for example, packet-based communication) betweencomputer system 1000 and one or more other computer systems 1000 or oneor more networks. As an example and not by way of limitation,communication interface 1010 may include a network interface controller(NIC) or network adapter for communicating with an Ethernet or otherwire-based network or a wireless NIC (WNIC) or wireless adapter forcommunicating with a wireless network, such as a WI-FI network. Thisdisclosure contemplates any suitable network and any suitablecommunication interface 1010 for it. As an example and not by way oflimitation, computer system 1000 may communicate with an ad hoc network,a personal area network (PAN), a local area network (LAN), a wide areanetwork (WAN), a metropolitan area network (MAN), or one or moreportions of the Internet or a combination of two or more of these. Oneor more portions of one or more of these networks may be wired orwireless. As an example, computer system 1000 may communicate with awireless PAN (WPAN) (such as, for example, a BLUETOOTH WPAN), a WI-FInetwork, a WI-MAX network, a cellular telephone network (such as, forexample, a Global System for Mobile Communications (GSM) network), orother suitable wireless network or a combination of two or more ofthese. Computer system 1000 may include any suitable communicationinterface 1010 for any of these networks, where appropriate.Communication interface 1010 may include one or more communicationinterfaces 1010, where appropriate. Although this disclosure describesand illustrates a particular communication interface, this disclosurecontemplates any suitable communication interface.

In particular embodiments, bus 1012 includes hardware, software, or bothcoupling components of computer system 1000 to each other. As an exampleand not by way of limitation, bus 1012 may include an AcceleratedGraphics Port (AGP) or other graphics bus, an Enhanced Industry StandardArchitecture (EISA) bus, a front-side bus (FSB), a HYPERTRANSPORT (HT)interconnect, an Industry Standard Architecture (ISA) bus, an INFINIBANDinterconnect, a low-pin-count (LPC) bus, a memory bus, a Micro ChannelArchitecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, aPCI-Express (PCIe) bus, a serial advanced technology attachment (SATA)bus, a Video Electronics Standards Association local (VLB) bus, oranother suitable bus or a combination of two or more of these. Bus 1012may include one or more buses 1012, where appropriate. Although thisdisclosure describes and illustrates a particular bus, this disclosurecontemplates any suitable bus or interconnect.

Herein, a computer-readable non-transitory storage medium or media mayinclude one or more semiconductor-based or other integrated circuits(ICs) (such, as for example, field-programmable gate arrays (FPGAs) orapplication-specific ICs (ASICs)), hard disk drives (HDDs), hybrid harddrives (HHDs), optical discs, optical disc drives (ODDs),magneto-optical discs, magneto-optical drives, floppy diskettes, floppydisk drives (FDDs), magnetic tapes, solid-state drives (SSDs),RAM-drives, SECURE DIGITAL cards or drives, any other suitablecomputer-readable non-transitory storage media, or any suitablecombination of two or more of these, where appropriate. Acomputer-readable non-transitory storage medium may be volatile,non-volatile, or a combination of volatile and non-volatile, whereappropriate.

Miscellaneous

Herein, “or” is inclusive and not exclusive, unless expressly indicatedotherwise or indicated otherwise by context. Therefore, herein, “A or B”means “A, B, or both,” unless expressly indicated otherwise or indicatedotherwise by context. Moreover, “and” is both joint and several, unlessexpressly indicated otherwise or indicated otherwise by context.Therefore, herein, “A and B” means “A and B, jointly or severally,”unless expressly indicated otherwise or indicated otherwise by context.

The scope of this disclosure encompasses all changes, substitutions,variations, alterations, and modifications to the example embodimentsdescribed or illustrated herein that a person having ordinary skill inthe art would comprehend. The scope of this disclosure is not limited tothe example embodiments described or illustrated herein. Moreover,although this disclosure describes and illustrates respectiveembodiments herein as including particular components, elements,functions, operations, or steps, any of these embodiments may includeany combination or permutation of any of the components, elements,functions, operations, or steps described or illustrated anywhere hereinthat a person having ordinary skill in the art would comprehend.Furthermore, reference in the appended claims to an apparatus or systemor a component of an apparatus or system being adapted to, arranged to,capable of, configured to, enabled to, operable to, or operative toperform a particular function encompasses that apparatus, system,component, whether or not it or that particular function is activated,turned on, or unlocked, as long as that apparatus, system, or componentis so adapted, arranged, capable, configured, enabled, operable, oroperative.

What is claimed is:
 1. A method comprising, by a computing device:receiving, from a client system of a first user of an online socialnetwork, an unstructured text query inputted by the first user;identifying, based on the unstructured text query, one or more objectsassociated with the online social network matching at least a portion ofthe unstructured text query; accessing a context-free grammar modelcomprising a plurality of grammars, each grammar comprising one or morenon-terminal tokens and one or more query tokens, each grammar being anordered sub-tree adjoining one or more other grammars via a non-terminaltoken; generating one or more structured queries, each structured querycorresponding to a selected grammar of the context-free grammar model,wherein each structured query is based on a natural-language stringgenerated by the selected grammar, each structured query comprising atleast one query token corresponding to each of the identified object;and sending, to the client system of the first user, one or more of thestructured queries as suggested queries for display to the first user inresponse to the unstructured text query inputted by the first user. 2.The method of claim 1, further comprising: accessing a social graphcomprising a plurality of nodes and a plurality of edges connecting thenodes, each of the edges between two of the nodes representing a singledegree of separation between them, the nodes comprising: a first nodecorresponding to the first user; and a plurality of second nodescorresponding to a plurality of objects associated with the onlinesocial network, respectively.
 3. The method of claim 1, wherein theplurality of grammars of the context-free grammar model is a grammarforest organized as an ordered tree comprising a plurality ofnon-terminal tokens and a plurality of query tokens, each grammar beingan ordered sub-tree adjoining one or more other grammars via anon-terminal token.
 4. The method of claim 3, further comprising:identifying, based on the identified objects, one or more query tokensin one or more grammars of the grammar forest, each identified querytoken corresponding to at least one of the identified objects; andselecting one or more grammars of the grammar forest, each selectedgrammar comprising at least one query token corresponding to each of theidentified objects.
 5. The method of claim 4, wherein selecting one ormore grammars comprises: traversing, for each identified query token,the grammar forest to identify one or more non-terminal tokens thatintersect with the traverse of one or more other identified querytokens; and selecting one or more of the grammars in the semantic treeadjoining the identified non-terminal tokens.
 6. The method of claim 4,wherein selecting one or more grammars comprises: generating a semantictree corresponding to the unstructured text query, the semantic treecomprising an intersect token and one or more query tokens, each querytoken connecting to the intersect by zero or more non-terminal tokens;analyzing the grammar forest to identify one or more sets ofnon-terminal tokens and query tokens that substantially match thesemantic tree, each set having a non-terminal token corresponding to theintersect token; and selecting one or more of the grammars in thegrammar forest adjoining the non-terminal tokens corresponding to theintersect token.
 7. The method of claim 1, further comprising generatinga query command based on the unstructured text query.
 8. The method ofclaim 1, wherein generating one or more structured queries comprises:generating, for each selected grammar, a natural-language string basedon the selected grammar, wherein the natural-language string comprisesthe one or more query tokens of the selected grammar; and rendering, foreach natural-language string, a structured query based on thenatural-language string, wherein the structured query comprisesreferences to each identified objects corresponding to query tokens ofthe selected grammar.
 9. The method of claim 1, wherein the unstructuredtext query comprises one or more n-grams, and wherein each of theidentified objects corresponds to at least one of the n-grams.
 10. Themethod of claim 9, wherein each n-gram comprises one or more charactersof text entered by the first user.
 11. The method of claim 9, whereineach n-gram comprises a contiguous sequence of n items from the textquery.
 12. The method of claim 9, wherein identifying one or moreobjects comprises: determining a score for each n-gram that indicatesthat the n-gram corresponds to an object associated with the onlinesocial network; and selecting one or more objects having a score greaterthan a threshold score, each of the selected objects corresponding to atleast one of the n-grams.
 13. The method of claim 12, wherein the scorefor each n-gram is a probability that the n-gram corresponds to anobject associated with the online social network.
 14. The method ofclaim 1, further comprising: determining a score for one or moregrammars of the plurality of grammars; and wherein generating one ormore structured queries comprises generating one or more structuredqueries corresponding to each grammar having score greater than agrammar-threshold score.
 15. The method of claim 14, wherein determiningthe score for each grammar is based on a degree of separation in asocial graph between the first user and at least one identified objectcorresponding to at least one query token of the grammar.
 16. The methodof claim 14, wherein determining the score for each grammar is based ona search history associated with the first user.
 17. The method of claim1, wherein the structured queries are displayed in a user interface ofan application associated with the online social network installed onthe client system of the first user.
 18. The method of claim 1, whereinthe structured queries are displayed in a webpage accessed by a webbrowser on the client system of the first user.
 19. One or morecomputer-readable non-transitory storage media embodying software thatis operable when executed to: receive, from a client system of a firstuser of an online social network, an unstructured text query inputted bythe first user; identify, based on the unstructured text query, one ormore objects associated with the online social network matching at leasta portion of the unstructured text query; access a context-free grammarmodel comprising a plurality of grammars, each grammar comprising one ormore non-terminal tokens and one or more query tokens, each grammarbeing an ordered sub-tree adjoining one or more other grammars via anon-terminal token; generate one or more structured queries, eachstructured query corresponding to a selected grammar of the context-freegrammar model, wherein each structured query is based on anatural-language string generated by the selected grammar, eachstructured query comprising at least one query token corresponding toeach of the identified object; and send, to the client system of thefirst user, one or more of the structured queries as suggested queriesfor display to the first user in response to the unstructured text queryinputted by the first user.
 20. A system comprising: one or moreprocessors; and a memory coupled to the processors comprisinginstructions executable by the processors, the processors executing theinstructions to: receive, from a client system of a first user of anonline social network, an unstructured text query inputted by the firstuser; identify, based on the unstructured text query, one or moreobjects associated with the online social network matching at least aportion of the unstructured text query; access a context-free grammarmodel comprising a plurality of grammars, each grammar comprising one ormore non-terminal tokens and one or more query tokens, each grammarbeing an ordered sub-tree adjoining one or more other grammars via anon-terminal token; generate one or more structured queries, eachstructured query corresponding to a selected grammar of the context-freegrammar model, wherein each structured query is based on anatural-language string generated by the selected grammar, eachstructured query comprising at least one query token corresponding toeach of the identified object; and send, to the client system of thefirst user, one or more of the structured queries as suggested queriesfor display to the first user in response to the unstructured text queryinputted by the first user.